Genesis comes with a useful function called genesis_custom_loop()
to output elements like entry header, entry content and entry footer when you want to write a custom query.
If you would like to make any changes like showing/hiding certain elements in the loop or moving them around, it is not sufficient just to do so and call the genesis_custom_loop()
with your query arguments. You also need to remember to undo or reverse your actions. Not doing this will affect other loops and may have undesirable consequences.
In this tutorial, I illustrate this with an example of displaying 1 latest post from a portfolio
custom post type below the header on the front page.
We will first create a function based on genesis_do_post_image()
to display linked (to the entry permalink) image in a specific medium_large
size.
Then in a function hooked to genesis_after_header
, we shall
- specify the CPT name, the number of posts to be fetched in an
$args
array and setno_found_rows
to true to speed up the WordPress query 1. - add a custom
featured-portfolio
class to the entry for easy CSS targeting. - do these loop actions: replacing Genesis archive image with our custom one, relocating entry title from entry header to entry content - above the content and removing the post info.
- run
genesis_custom_loop
with$args
. - reverse the custom loop actions.
Here's the code in child theme's functions.php that does the above:
To view the full content, please sign up for the membership.
Already a member? Log in below or here.