One Request, Many Possible Templates
Every time someone visits a page on a WordPress site, WordPress has to decide which PHP file should generate that page's HTML. It does this by checking a specific, predictable order of filenames inside the active theme — the first matching file it finds wins. This system is the template hierarchy.
Understanding this order means you can create a file with a very specific name and know exactly which pages it will control, without touching anything else on the site.
- ✓WordPress checks a fixed, predictable order of filenames for every request.
- ✓More specific filenames are checked before general fallback files.
- ✓
index.phpis the final fallback every theme must include.
The Files You'll See Most Often
Themes rarely use every possible template file — but these cover the vast majority of real sites.
The site's homepage, taking priority over every other template.
An individual blog post's page.
An individual static page, like About or Contact.
A listing page — category, tag, date, or author archives.
The universal fallback used when no more specific file exists.
WordPress always asks "is there a more specific file for this exact page?" before falling back to something more general.
Targeting a Single Post Type or Slug
// Single "testimonial" post type, checked in this order: single-testimonial.php // most specific — just this post type single.php // general single-post fallback singular.php // fallback shared by posts and pages index.php // final fallback for any request
The same pattern applies to pages, archives, and categories — add the post type or slug to the filename to target it precisely.
Building a Template for One Page
page-contact.php for the Contact page.How Precise Should You Get?
Common Template Hierarchy Mistakes
Breaking Down What You Just Learned
A fixed lookup orderWordPress checks filenames from most specific to most general for every request.
index.php is the ultimate fallbackEvery theme must include it, since nothing else is guaranteed to exist.
Filenames encode targetingAdding a slug or post type name, like page-contact.php, narrows exactly what a file controls.
Child theme files take priorityA template in the child theme is used before the same-named file in the parent.
Only override what's differentReserve targeted templates for pages that genuinely need a unique layout.
Try It Yourself
Duplicate page.php in your child theme as page-about.php, add a visible change like a background color, and confirm only the About page shows the new style.
Build a Targeted Template
Giving one page of your capstone site a unique layout
By the end of today, one page on your capstone site should be running its own dedicated template file.
- Pick a page that would benefit from a different layout than the rest of the site.
- Copy the relevant base template into your child theme.
- Rename it following the template hierarchy naming pattern.
- Make one visible change to confirm the new file is loading.
- Check that no other pages were affected by the change.
Recap
The fixed order WordPress uses to pick which file builds a given page.
The universal fallback template every theme is required to have.
A template named for one exact page, post type, or category.
Templates in the child theme override matching files in the parent.
Key Takeaways
- WordPress selects a page's template using a fixed, predictable lookup order.
- Every theme needs an index.php as the final fallback for any request.
- Filenames like page-contact.php or single-testimonial.php target one specific page or post type.
- Templates placed in a child theme always take priority over the same file in the parent.
- Reserve targeted templates for pages that truly need a different layout, not every page.