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
Then in a function hooked to
genesis_after_header, we shall
- specify the CPT name, the number of posts to be fetched in an
$argsarray and set
no_found_rowsto true to speed up the WordPress query 1.
- add a custom
featured-portfolioclass 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.
- 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.