A theme consists of many files, this can get very confusing very fast. What files are needed? What files runs when and why? Here are the explanations and tips about WordPress template files.

First things first, what is a template exactly? A template is a PHP file that is a part of a theme. For example, there is a template for displaying the home page, one for displaying pages and another one for displaying posts.

What Are The Existing WordPress Tempaltes?

Here is a list of the existing WordPress templates that can be used in themes:

Here is a very useful image provided by WordPress Codex (click to enlarge):

WordPress Template Hierarchy

Custom Templates

There are two main types of custom WordPress templates.

The first one are templates that WordPress looks for automatically, and if one is found it will be used. What the heck am I talking about?
If you have a category called “News” with the ID of 512 and you want the archive page of that category to have it’s own unique template you can create a new template file called category-512.php in the theme’s folder. And WordPress will use it.

This is the list of custom wordpress templates you can use:

WordPress Custom Template Drop Down

Now for the second type of WordPress custom templates.

Let’s say you have more then one page* you want to be displayed in a different way then the others. How do you do that?
Create a new file called whatever.php at your theme’s folder and inside write whatever you want instead of single.php or index.php (depending what displays the single posts at your theme).
Add this comment to the top of the file:

<?php
/*
Template Name: The Whatever Template Yo
*/
?>

(Of course change The Whatever Template Yo to the new template’s name)

Now edit (or create) the pages which you want to use this template and in the right side pick the desired template from the drop down menu. Just like in the screenshot at the right side.

*If you want to do this for posts rather then pages then you will find the Custom Post Template plugin very useful.

Any questions/corrections? Comments are always welcome.

Search terms:

4 Responses to WordPress Templates Complete Guide & Tips

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting