◦ Comprehensive security
◦ 24/7 support
WordPress Guide → Development → Template Hierarchy
WordPress template hierarchy explained for new developers
If you’re building or customizing themes, understanding WordPress’ template hierarchy is essential. It’s the system WordPress uses to decide which PHP file to load when rendering a given page. Once you understand the logic, you can build custom templates that match specific content types, categories, or even post slugs—without writing extra conditional code.
Let’s break it all down and walk through exactly how it works.
Get fast, reliable hosting for WordPress
Power your site with the industry’s fastest, most optimized WordPress hosting
What is the WordPress template hierarchy?
WordPress doesn’t just randomly choose which template file to use—it follows a strict hierarchy. This system checks the context of the current request (like a single post, a page, a category archive, etc.) and selects the most specific matching template available in your theme folder.
If it doesn’t find a file that fits perfectly, it falls back to more general ones until it reaches index.php, the default catch-all.
Example: Someone visits a category archive for “News.” WordPress looks for:
- category-news.php (matches category slug)
- category-7.php (matches category ID)
- category.php (generic category template)
- archive.php (general archive template)
- index.php (fallback for everything)
The core logic behind the hierarchy
WordPress determines the type of query being requested based on the URL or internal logic. It could be:
- A static front page
- A blog post listing
- A single post or page
- An archive for a category, tag, or author
- A custom post type
- A search result or 404 page
For each of these, WordPress checks the most specific template, then falls back layer by layer.
Let’s break it down with real file names.
Template hierarchy breakdown by page type
Each of these sections explains the hierarchy in order, from most specific to most general.
Front page
If you’ve set a static front page in Settings > Reading:
- front-page.php
- page-{slug}.php
- Page.php
- singular.php
- index.php
If your homepage is the blog listing:
- home.php
- index.php
Single post
For standard blog posts:
- single-post.php
- single.php
- singular.php
- index.php
Custom post type (CPT)
For example, if you register a post type called event:
- single-event.php
- single.php
- singular.php
- index.php
Static page
For individual pages:
- page-about.php (matches slug)
- page-42.php (matches ID)
- page.php
- singular.php
- index.php
Category archive
When visiting a category archive:
- category-news.php
- category-7.php
- category.php
- archive.php
- index.php
Tag archive
For tag pages:
- tag-deals.php
- tag-9.php
- tag.php
- archive.php
- index.php
Author archive
For author profile pages:
- author-johndoe.php
- author-3.php
- author.php
- archive.php
- index.php
Date archive
For year/month/day archive URLs:
- date.php
- archive.php
- index.php
Search results
For search result pages:
- search.php
- index.php
404 error
If no content matches the query:
- 404.php
- index.php
Visualizing the hierarchy
The hierarchy isn’t something you need to memorize completely. One of the most helpful resources is the WordPress template hierarchy diagram, a flowchart-style overview of how WordPress picks templates.
You can also use tools like What The File (a browser extension) to inspect which template is being used on a live site.
Using template parts for reusable code
While the template hierarchy picks the main file, you can use get_template_part() to include reusable components inside those files. For example:
<?php get_template_part(‘partials/content’, get_post_type()); ?>
This will include partials/content-post.php or partials/content-event.php based on the post type.
It’s great for modularizing your theme—headers, footers, navigation, loops, and more can live in separate files, making your code cleaner and easier to manage.
Best practices for working with the hierarchy
- Always include index.php in your theme—it’s the final fallback.
- Use specific templates when you want full control over layout or logic.
- Keep your template folder organized with subfolders like partials/ or template-parts/.
- When working with custom post types or taxonomies, match your file names to their slugs.
Next steps for mastering the WordPress template hierarchy
The template hierarchy is the foundation for building dynamic, well-organized themes in WordPress. Once you understand how it works, you can take full control over how your content looks and behaves on the front end.
To put this knowledge into practice, start editing or building your own theme. Try customizing category templates, creating a unique homepage, or splitting your layout into modular template parts.
Ready to take the training wheels off your WordPress site? Upgrade to professional hosting and see how better speeds, security, and reliability provide a foundation for a website and a brand that people find engaging and trustworthy. Liquid Web’s WordPress hosting options configure business-class servers and support plans specifically for WordPress websites.
Click through below to explore all of our WordPress hosting options, or chat with a WordPress expert right now to get answers and advice.
Additional resources
What is managed WordPress hosting? →
Get details and decide if managed WordPress hosting is right for you.
What is the WordPress loop? →
Learn how the WordPress Loop works to display posts dynamically on your website.
A complete guide to WordPress shortcodes →
Shortcodes make life easier. Learn how to get started!