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
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.