WordPress will check for template files with very specific names, in a very specific order, before finally falling back to index.php; this serves as a sort of catch-all for rendering pages when no particular templates are defined.

Quick-and-dirty Template Hierarchy Reference

Here's a quick reference to the filenames WordPress looks for when it renders each type of page.

Home Page

In WordPress 3.0, a blog administrator can specify whether to show the latest posts or a static page as the blog's home page. The templates WordPress looks for, in order, are:

1. front-page.php

2. page.php or home.php, depending on what was chosen in the blog's settings

3. index.php

WordPress 2.x lacks this feature, so the order will simply be:

1. home.php

2. index.php

Single Posts

1. single-posttype.php, where posttype represents one of WordPress 3.0's post types. For example, if your blog was about recipes, and you had a post type called Recipes, WordPress would look for a template called single-recipes.php.

2. single.php

3. index.php

Single Pages

1. WordPress will first look for a template specified in the page's template setting—more on this later.

2. page-slug.php, where slug is the slug specified on the page. For example, if you had a page called About, WordPress would first look for page-about.php.

3. page-id.php, being the numeric ID of the page. If your About page had an ID of 2, then the template WordPress would look for is page-2.php.

4. page.php

5. index.php


1. MIMEtype.php, where MIMEtype represents the broad type of your attachment—like audio.php, image.php, text.php, or video.php

2. attachment.php

3. index.php

What are mimes doing in WordPress?

On the Internet, the format of a piece of data, such as a document or a web page, is specified by a header called a MIME type. MIME stands for Multipurpose Internet Mail Extension, although MIME headers are in use for more than just mail. Common MIME types for familiar documents include text/html for HTML documents, application/zip for ZIP documents, image/gif for GIF images, and so on.

Category Archives

1. category-slug.php, where slug is the category's slug.

2. category-id.php, where id is the category's numeric ID.

3. category.php

4. archive.php

5. index.php

Tag Archives

1. tag-slug.php, where slug is the tag's slug.

2. tag-id.php, where id is the tag's numeric ID.

3. tag.php

4. archive.php

5. index.php

Taxonomy Archives

Custom taxonomies are new to WordPress 3, so these templates are never called by WordPress 2.

1. taxonomy-taxonomyname-term.php, where taxonomyname represents the slug of the custom taxonomy, and term represents that of the term. If your taxonomy was called Cheeses and your term was Brie, then WordPress will look for taxonomy-cheese-brie.php when listing items from that term.

2. taxonomy-taxonomyname.php, similar to the above, but without the term.

3. taxonomy.php

4. archive.php

5. index.php

Author Archives

1. author-nicename.php, where nicename is the author's username made suitable for URLs—all lowercase, with spaces transformed into hyphens. If an author's username was Kelly Steele, then the template WordPress would look for would be author-kelly-steele.php (WP3).

2. author-id.php, where the id is the author. If Kelly's ID were 3, then author-3.php would be the template WordPress would choose (WP3).

3. author.php

4. archive.php

5. index.php

Date-based Archives

1. date.php

2. archive.php

3. index.php

Search Pages

1. search.php

2. index.php

404 Page

1. 404.php

2. index.php

That sure is a lot of stuff to remember. Fortunately, Rami from wp-tricks1 has made a neat diagram2 that explains the template hierarchy visually. You might like to print it and use it as a cheat sheet!

New versions of WordPress arrive roughly every three to four months, and new template names could be added to any of the upcoming releases. Check the WordPress Codex Template Hierarchy page3 for the latest and greatest.

The Template Hierarchy and Child Themes

When you're using a child theme, the template hierarchy becomes a little more complex. WordPress will first look for the most specific template in your child theme, then to the parent, then back to

Always in Motion Is the Future

1 http://www.wp-tricks.co.il/

2 http://codex.wordpress.org/images/l/18/Template_Hierarchy.png

3 http://codex.wordpress.org/Template_Hierarchy

the child for the next most specific, then back to the parent again—all the way down the line until it finally falls back on the parent's index.php file. Is your head spinning yet? Here's an example.

Let's say you have an FAQ page with a slug of faq and an ID of 12. WordPress will first check whether you've specified a template in the page's settings; if not, it checks for the following files in order:

1. the child theme's page-faq.php

2. the parent's page-faq.php

3. the child again for page-12.php

4. the parent's page-12.php

5. the child's page.php (Are we detecting a pattern here?)

6. the parent's page.php

7. the child's index.php

8. finally, the parent's index.php

Of course, WordPress can do all this in the blink of an eye.

Was this article helpful?

0 0

Post a comment