I recently updated the front page of nxtab.co.uk to show posts from the key blog categories, previously the site was showing just the last couple of posts but I wanted more of the rich content to be brought to the fore.
The Genesis framework is nicely setup to allow a variety of different front page configurations and so getting the mix of categories onto the front page was simple enough. Genesis users can find out more through the excellent StudioPress documentation.
Since implementing the new front page I have already noticed a decrease in bounce rate and a general overall increase in the number of pages viewed per visitor so this seems to have been a good move.
I then wanted to go a step further and link through to each of the site’s categories, the good news is that the Genesis featured post widget has an option to add this link in automatically. The bad news was that the links seemed poorly positioned and there was no spacing between the link and the next widget. It was effectively unusable.
Customising the Category Archive Link
To solve this problem I needed a way to customise the archive link inserted by the widget. Unfortunately there is no generic WordPress filter that can be used to update the contents of a widget and the Genesis Featured post plugin does not have any hooks or filters built in either (perhaps this is something they could add?).
Fortunately there is the 3rd party Genesis Featured Post Amplified widget that offers all the same functionality plus more.
The Amplified widget does include some hooks that we can definitely make use of to customise the category links in any way that we like.
Here’s how I did it:
- We’ll start by opening up your Genesis child theme functions.php file. We’re going to add some code here to hook into the widget and generate our new link.
- The hook we are going to use is: gfwa_after_category_more. There is also a hook called gfwa_category_more that allows you to hook into the conditional block itself. This seemed useful as it only fires if you have selected the “show category archive link” option in the widget, however I saw no way to edit the output.
- The gfwa_after_category_more will fire after this block, so if we elect not to show the link, and then add our own logic in at this point we can output any HTML we like.
- Here’s some sample code:
echo “<div style=’text-align:left’><a href=’http://www.nxtab.co.uk/category/applications/’>More Apps</a></div><p><br>”;
- So here we add our new action, this is a function that will be called for each instance of the widget.
- The function is passed a variable $instance by the widget, this is an array containing various properties of the widget. We can use this to tell which instance we are in and then output a link accordingly.
- In this example I have hard coded in a category, but there is no reason we couldn’t make this function generic so that it could work the same for any and all widgets placed on the front page.
- Here’s how it looks:
The real advantage of doing this is that we can now output any HTML we like at this point, so I’ve also created some funky looking buttons that should hopefully attract more clicks and encourage greater exploration of the site’s most useful pages.