The Wordpress Template Hierarchy is a critical part of truly understanding how your Wordpress blog works.

Have you ever wondered why some Wordpress themes have certain files while others do not?

A Wordpress theme requires only two files as I have discussed before, the index.php and style.css. If you took a basic Wordpress Theme and deleted all the files except those two in the theme folder, it would still work. However, the pages would basically look the same.

Now the question is, where do these other files come from? And how does Wordpress know which ones to look for? This is actually a very simple process. Wordpress uses a page hierarchy to choose which files to use for each type of page.

As an example if there is a single.php file, Wordpress will use that for the individual (single) post, if that file does not exist, it will use the Index.php file.

There are 10 basic Wordpress Theme pages, these are:

  • 404 (Not Found) page
  • Attachment page
  • Author page
  • Category page
  • Date page
  • Search Result page
  • Single Post page
  • Tag page
  • The Main (Index) page
  • WordPress Page

This gives us the ability to customize each type of page. This Wordpress Codex page explains the Hierarchy.

Let’s look at the Tag.php page as a more specific example.

The Tag page hierarchy goes like this.

  • The Tag Template with a matching slug. If the tag’s slug were sometag, WordPress would look for tag-sometag.php
  • tag.php
  • archive.php
  • index.php

So if your Wordpress theme does not have a Tag.php page you can easily copy the archive.php page to create a custom tag page, if you do not have a archive page, you could copy the index page to start your tag page.

To help you I have created a simple text file that lists the Wordpress heirarchy that you can download here.

So with just a little thought and practice it is very easy to create very unique pages for your Wordpress Theme.



Subscribe to CyberCoders RSS feed.

February 23rd, 2008 - By David