How to Use Template Parts in the Genesis Framework

Genesis is powerful because its actions and filters let you customize nearly every part of the framework.

Some of those actions relate specifically to the Genesis loop, which controls how posts are rendered on archive pages and single post views. Sridhar Katakam offers a helpful introduction to Genesis loop actions for additional background.

Template tags let you tailor the output depending on the current page context. For example, this Genesis code displays a featured image for posts on archive pages:

On line 15 you can see the check for ! is_singular(), which prevents the featured image from being output at the top of single posts.

add_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
add_action( 'genesis_post_content', 'genesis_do_post_image' );
/**
 * Echo the post image on archive pages.
 *
 * If this an archive page and the option is set to show thumbnail, then it gets the image size as per the theme
 * setting, wraps it in the post permalink and echoes it.
 *
 * @since 1.1.0
 */
function genesis_do_post_image() {

	if ( ! is_singular() && genesis_get_option( 'content_archive_thumbnail' ) ) {

		$img = genesis_get_image( array(
			'format'  => 'html',
			'size'    => genesis_get_option( 'image_size' ),
			'context' => 'archive',
			'attr'    => genesis_parse_attr( 'entry-image', array(
				'alt' => get_the_title(),
			) ),
		) );

		if ( ! empty( $img ) ) {

			genesis_markup( array(
 				'open'    => '',
 				'close'   => '',
 				'content' => wp_make_content_images_responsive( $img ),
 				'context' => 'entry-image-link',
 			) );

 		}

	}

}

That approach is straightforward, but it becomes limiting as sites grow more modular. I build a reusable “post summary” module that I want to use both on archive pages and as related posts on single post pages. Template tags only know about the current request context (archive, single, search, etc.), not the specific module or component that’s rendering a post summary.

img 6732 1

What are template parts

Template parts, sometimes called template partials, are small theme files that hold reusable chunks of markup and PHP. They make it easy to render the same piece of UI in multiple places without duplicating code.

Below is the archive partial I use to output a post summary. It is typically used on archive pages but also reused when rendering related posts.

';

	echo '' . get_the_post_thumbnail( get_the_ID(), 'medium' ) . '';

	echo '
'; echo '

' . get_the_title() . '

'; echo '
'; echo '
'; the_excerpt(); echo '

Read Moreof ' . get_the_title() . '

'; echo '
'; echo '';

When I need to show related posts, I run a custom query and reuse the same archive partial inside the loop. This keeps the markup consistent and reduces maintenance.

 ea_get_related_posts( 3 ),
		'orderby'   => 'post__in',
	) );
  
	if( $loop->have_posts() ):
		while( $loop->have_posts() ): $loop->the_post();
			get_template_part( 'partials/archive' );
		endwhile;
	endif;
	wp_reset_postdata();
}
add_action( 'genesis_after_entry', 'be_related_posts' );

Using on archive pages

In my more recent Genesis child themes I replace the default Genesis loop on archive pages with a loop that calls template parts. This allows the main Genesis hooks to remain focused on the primary singular content while enabling flexible, reusable modules for lists and related content.

With that setup, many Genesis loop hooks only run for the main post on single views. You can rely on hooks like genesis_entry_header firing in the singular context while related post modules use their own template parts and context-specific markup.

Here is the code I use to swap in an archive loop that renders template partials:

You can add this code directly to functions.php or include it from a separate PHP file. The structure makes it simple to swap in different partials and contexts via filters.

For a practical example, refer to my EA Genesis Child base theme, which implements this pattern and demonstrates how template parts can streamline theme development.

Downside

One trade-off: plugins that expect Genesis loop actions and filters on archive pages may not behave the same once you replace the loop with template parts. Those plugins often hook into Genesis actions to add features; if those hooks no longer run on archives, the plugin-provided functionality may be missing.

For example, a grid layout plugin might rely on post_class() and the Genesis featured image functions to add column classes or set featured image sizes. When the archive loop no longer triggers the same hooks, the plugin cannot apply those modifications and the grid may not render as intended.

If your workflow depends heavily on plugins that modify the default Genesis loop, replacing the loop with template parts may not be the right choice. But if you prefer a modular, component-based approach to building Genesis child themes, template parts provide a clean, reusable way to manage post summaries and related content while keeping markup consistent across contexts.