WordPress 3 Template Hierarchy

This chart is one entire page in our book, but I thought it would be good to focus on specifically. Template hierarchy has gotten a bit more advanced since the last time we covered it.

The idea is that WordPress will look for files in a theme to use to render the current page in a specific order. For example, let say you have a page for showing posts from a certain category like this. On this site, all our category pages are currently the same and use “archive.php” template. This file is pretty far down the hierarchy, and is shared with other types of views, for example, tag pages.

If we wanted to differentiate our category pages from our tag pages, we could create a file in our theme called “category.php” and our site would instantly start using that template for these pages, without us having to do anything else. We could get even more specific, have theme files that are unique to the categories themselves! To make a page specific to our security category, we could make a file called “category-security.php” and our site would use that file when viewing that category page.

You could really get fancy with customized pages by having a good understanding of the template hierarchy! Do take care not to get too overly repetitive with your templates though. If you have 10 categories and want to have a different header on each, you may be better off using a single category.php file with conditional tags rather than 10 separate files.


This was based on this hierarchy list that was sent to me by Ptah Dunbar. Thanks Ptah!

  • 404
    1. 404.php
    2. index.php
  • Search
    1. search.php
    2. index.php
  • Tax
    1. taxonomy-{tax}-{term}.php
    2. taxonomy-{tax}.php
    3. taxonomy.php
    4. archive.php
    5. index.php
  • Home
    1. home.php
    2. index.php
  • Attachment
    1. mime.php
    2. type.php
    3. mime_type.php
    4. attachment.php
    5. single.php
    6. index.php
  • Single
    1. single-{post-type}.php
    2. single.php
    3. index.php
  • Page
    1. custom_template.php
    2. page-{slug}.php
    3. page-{id}.php
    4. page.php
    5. index.php
  • Category
    1. category-{slug}.php
    2. category-{id}.php
    3. category.php
    4. archive.php
    5. index.php
  • Tag
    1. tag-{slug}.php
    2. tag-{id}.php
    3. tag.php
    4. archive.php
    5. index.php
  • Author
    1. author-{author-nicename}.php
    2. author-{author-id}.php
    3. author.php
    4. archive.php
    5. index.php
  • Date
    1. date.php
    2. archive.php
    3. index.php
  • Archive
    1. archive.php
    2. index.php

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s