Revert to a standard loop on the home page, overriding the theme front-page.php template without editing it.
I recently created a website for my wife’s new food blog. Most of her customisation requests were simple ones that I do on many Genesis based websites (e.g. footer credits, add stats code, some custom CSS and post meta).
After a short while she noticed that the home page, which used a widget to list recent posts, did not display a link to older posts. While the blog page displays a grid of the 12 most recent posts, its layout is quite different from the home page. The home page displays the title, photo and a few lines of content from each post while the blog page is just title and photo.
The problem was that the widget was designed to display posts from a single category and provide a link to other posts in that category. When used to display posts from all categories this link is not shown.
I looked in the theme’s front-page.php template file and saw that it simply replaced the genesis_do_loop with its function that just displays the 3 home page widget areas. As we were only using one widget area, overriding this entire function would be okay.
Undo the theme code and change the loop
I ran my code in the ‘genesis_meta‘ action, after the theme had run its code. The first step was to undo its removal of genesis_do_loop. I then removed some default behaviour (using remove_action() because Genesis adds the functionality with add_action()) and added some functions to mimic the settings of the widget that we had been using e.g. limit to 5 posts, display a medium centre-aligned image (adapted from Genesis core code) and display 250 characters of post content.
The pagination was set to numeric (1, 2, 3 etc instead of Previous/Next) but my wife wanted Previous/Next on the home page. In fact I customised this to ‘Older posts’ and ‘Newer posts’ for just the home page.
The code
I expect that many Genesis developers would suggest editing the theme’s front-page.php file but I don’t like editing Genesis child theme files. I am able to override most things via a plugin. This means that the theme is untouched and any theme update can be applied without any concern.
Leave a Reply