• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Genesis Snippets

A reference for Genesis theme developers

  • Home
  • Archives
  • Search Genesis Snippets

loop

Replace default loop with custom loop

September 15, 2012 By David Wang

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().

Filed Under: Genesis Tagged With: genesis_custom_loop, loop

Primary Sidebar

Brought to you by ClickWP
Buy the Genesis Theme Framework

Who’s behind this?

Hi! I'm David and I'm a big Genesis fan. I've been using it in all my projects and have found it to be super powerful.

I started this site to keep track of all the snippets that I've been using in my projects and so that it's easy for me to find them again instead of digging through my old project files.

Help support this site by buying Genesis with our affiliate links. Thanks!

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 354 other subscribers

Browse Snippets

branding cache comments css custom post type doctype entry footer entry header favicon featured image genesis_custom_loop images internet explorer jetpack loop media menu metabox minify navigation oembed page layouts performance plugin integration post thumbnail shortcode sidebars theme options widget areas widgets WooCommerce WordPress
Everything you need to support your online business
Take WordPress further with the Genesis framework

Copyright © 2025 · Genesis Sample On Genesis Framework · WordPress · Log in