I don’t know what was the reason you choose to work with WordPress, but it is rather obvious this CMS is very popular. One of the keys to its popularity is that because of using themes the website creation process becomes very easy. Every WordPress website theme is a set of page templates. If to say in simple words, those templates are ready-made pages with design, structure, and functions. When you, as the user, choose some theme the WordPress put the content you added (texts, pictures, videos, etc.) to the template of a specific page.
For example, you write a post for your blog. You typed the text, choose the featured picture and other images, and then pushed the “Publish” button. When you or the visitor of your website, open that post, WordPress chooses the page template from the theme folder, add your content to the appropriate fields and show that composition.
But how does WordPress know what to show? How does it choose the right template for a concrete type of page? That’s where the WordPress template hierarchy comes into play.
When you try to open some page, WordPress begins to seek for a template that matches that page. And WordPress template hierarchy is a set of rules that determine the order in which WordPress does that seeking. As Wikipedia says: “A hierarchy is an arrangement of items in which the items are represented as being "above", "below", or "at the same level as" one another”. So template hierarchy defines what templates will be the first in the column, what will be checked in the second position and so on. WordPress checks if the first file in the column exists, then check second one, third and continues until it finds the existing file.
There are four files that always lies at the bottom of the checking table:
But only one of them is crucial for the functioning of the website. There are two files that are an absolute must for every website – index.php and style.css. What does it mean for you? It means that WordPress will always come to check the index.php file if there won’t be any other file that could define the design of the page. And that also means that a template you create by your own hands has to have an index.php file. Even if there won’t be any other template – without that one nothing will work.[tweet_box]There are two files that are an absolute must for every website – index.php and style.css.[/tweet_box]
In fact, you won’t need it, if you are not going to customize the theme of your website. Or, at least, you are not going to customize its code directly. There are lots of ready-made WordPress templates you can get and use. In fact, you can subscribe for ONE service and get access to all TemplateMonster bestseller themes. You will be able to download as many templates you would like to, try them all and choose the one that fits your business and taste the best of all. All the themes presented on the TemplateMonster marketplace are created by professionals, so you will have to do only minor customization and then you don't need to know the WordPress template hierarchy at all.
Knowledge of the WordPress template hierarchy will be useful for people who create themes. It will be also necessary if you, in general, are satisfied with the template but don’t like one concrete page and want to replace it with the one you created or downloaded (that will create a child theme, relative to the original one).
WordPress template hierarchy is necessary for the theme creator because it gives him an understanding of what files he has to create and how to name them. The wrong naming or absence of some important file will cause errors and bugs. But that’s enough talking – let’s move on to the template hierarchy by itself.
If you have a big blog and publish not only the articles you wrote by yourself but also the texts of other writers each of them has to have his own separate page. On that page, the user can see a list of articles, written by that author and also, maybe, some information about the writer, his experience and interests.
It is convenient both for you and for the readers to sort the blog posts into understandable categories. When the user clicks on the category title he wants to see a page with the list of articles of the appropriate category. There also could be a description of the category, the list of authors or the rate of most popular articles.
Sometimes it could be quite great to sort the articles according to the post types, like “review”, “short story” or “long read”. After clicking to the post type the reader will find all the articles matched with that type.
You could use not a default way of sorting articles like tags or categories but create your own. In that case, if you would like to make the articles list page more interesting you should create some special files for it.
All the post you or your authors write for the blog is automatically matched with some date. Clicking on the day, month or year the user has to be able to look at the list of posts that were written that concrete day, month or year.
Tags are one of the most popular ways of matching the texts now. You can create any tags you want and like. It is almost like categories but a little more fun and messy. When you click the tag you expect to see the list of posts matched with that tag.
There are three types of single post page – Custom post, Attachment post, and Blog post. When the user opens one of your posts to take a closer look – the WordPress will use a special design file for it. In fact, every post can have its own design and style, but I guess you won’t have time and desire to customize each of them. Especially if you have a big blog with a huge number of posts.
For attachment post:
For custom post:
For the blog post:
And they all come up to these three files:
There are three types of the front page you can choose from. The first one – a custom page created especially for that purpose. Second – one of the pages of the site. Third – the list of posts you have in your blog.
One of the most important pages on your website (except, maybe, “About us” page) is “404” or “Not Found” page. The user could always do something wrong and land on it, so it is great to make it witty and informative. So, it will be really profitable for your business if you will create an appropriate file for this page in the WordPress template hierarchy.
When a user seeks for something on your page – he sees the results of searching on a special page. You can create a special file to make that page look the way you would like it to.
When the user wants to take a look at one of the embeds on the separate page WordPress start checking the templates in the following order:
That is all about the WordPress templates hierarchy – I showed you how the template for any page is chosen. Now, when you would like to create your own website theme – you have an understanding of what files do you need to create. If you found this article useful or have some advice or review – please feel free to leave a comment in the section below.
Subscribe to our newsletter and access exclusive content and offers available only to MonsterPost subscribers.