Genesis comes with a handy function called genesis_custom_loop()
. It’s an easy way for you to create a new loop without having to write all the code to create a new loop with WP_Query manually. Here’s how you can use it in your theme.
/** Replace the standard loop with our custom loop */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'child_do_custom_loop' );
function child_do_custom_loop() {
global $paged; // current paginated page
global $query_args; // grab the current wp_query() args
$args = array(
'category__not_in' => 42, // exclude posts from this category
'paged' => $paged, // respect pagination
);
genesis_custom_loop( wp_parse_args($query_args, $args) );
}
The above will spit out a loop that excludes posts from category ID 42 and displays posts from the current paginated page (i.e. /page/2
and so on). The wp_parse_args()
function combines the $args
array with the current $query_args
for that page. The $args
array should accept all WP_Query parameters.
Replace with a non-Genesis loop
If you need to completely customize the loop, if you are displaying events or a ecommerce shop page for example, you don’t need to use the genesis_custom_loop()
function at all. Just write your own to replace it.
/** Code for custom loop */
function my_custom_loop() {
// code for a completely custom loop
}
/** Replace the standard loop with our custom loop */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'my_custom_loop' );
You can stick this code in functions.php
to affect all the loops in your site, or put it in a template file like date.php
or author.php
to limit it with the template hierarchy. If you do stick it in a template file, remember to end it with genesis()
.