9.3 Section-Specific Archetypes
Now, let’s get into the real meat of the matter: section-specific archetypes. These aren’t just page templates; they’re the DNA for the individual parts of your site. Think of them as the specialized tools in your workshop. You wouldn’t use a sledgehammer to drive a finishing nail, and you shouldn’t use a generic single.php template for everything. This is where WordPress’s template hierarchy earns its keep, and where you start to look like a genuine theme wizard.
The Single Post (single.php)
This is the workhorse for displaying a single post. The key here is context. A single.php file knows it’s displaying one post, so it can safely call the_post() and then go nuts with template tags like the_title(), the_content(), and the_post_thumbnail() without worrying about a loop. The most common rookie mistake? Forgetting to call wp_reset_postdata() if you run a custom query inside this template to show related posts or something. Don’t be that person. Your sidebar will start showing the wrong titles, and it’ll be a mess.
<?php
/**
* The template for displaying all single posts
*/
get_header();
?>
<main id="main">
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', get_post_type() );
the_post_navigation(); // Super useful for a "next/previous" post links.
// If comments are open or we have at least one comment, load the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</main>
<?php
get_sidebar(); // Maybe. Not every design needs a sidebar on a single post.
get_footer();
The beauty is in using get_template_part() to pull in a more specific content file, like template-parts/content-post.php. This keeps your single.php clean and lets you reuse that content block elsewhere.
The Page Template (page.php)
Pages are the “static” siblings of posts. They typically don’t have categories, tags, or dates displayed. Your page.php might look similar to single.php, but it often omits all that meta data. The critical thing to understand is the template hierarchy for pages. If a user assigns a custom page template from the WordPress admin, like “Full Width,” WordPress will look for page-fullwidth.php before it falls back to page.php. This is your secret weapon for creating unique layouts for specific pages.
<?php
/**
* The template for displaying all pages
*/
get_header();
?>
<main id="main" class="site-main">
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', 'page' ); // Specifically looks for content-page.php
// Want comments on a page? You can, but it's rare. Usually you'd remove this.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile;
?>
</main>
<?php
get_footer();
The Archive Template (archive.php)
This is your blog roll, your category list, your date archive—anything that shows a collection of posts. The main job here is to master The Loop. You’ll also want to use the_archive_title() and the_archive_description() to spit out the name of the category or tag you’re viewing. It’s a tiny function that does a ton of heavy lifting, and it’s criminally underused.
<?php
get_header();
?>
<main id="main">
<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="archive-description">', '</div>' );
?>
</header>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : ?>
<?php the_post(); ?>
<?php get_template_part( 'template-parts/content', get_post_format() ); ?>
<?php endwhile; ?>
<?php the_posts_navigation(); // Essential for pagination. ?>
<?php else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); // The "nothing found" template. ?>
<?php endif; ?>
</main>
<?php
get_sidebar();
get_footer();
The pitfall here is pagination. Always use the_posts_navigation() or the_pagination() instead of rolling your own. It respects the global $wp_query object and just works correctly.
The Front Page (front-page.php)
This is a weird one, and the hierarchy is confusing on purpose. If front-page.php exists, WordPress will use it for the site’s front page regardless of whether you’ve set the front page to show posts or a static page in Settings > Reading. This gives you ultimate control, but it also means this template has to be a mind-reader. You have to check what the setting is and act accordingly. It’s powerful, but it’s also a bit of a hack.
<?php
get_header();
?>
<!-- Your custom, incredible hero section goes here -->
<?php
// Check the reading setting.
if ( get_option( 'show_on_front' ) === 'posts' ) :
// The blog is set to the front page, so show a list of posts.
get_template_part( 'template-parts/content', 'blog' );
elseif ( have_posts() ) :
// It's set to a static page, so just show that page's content.
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', 'page' );
endwhile;
endif;
?>
<!-- Maybe a featured products section or something else custom -->
<?php
get_footer();
This template is where you break all the rules. It’s meant to be a unique landing page, not a repetition of your blog. Go wild, but document what you did because you’ll forget in six months. I promise.