Understanding the templates hierarchy

We've discussed that a WordPress theme comprises many file types including template pages. Template pages have a structure or hierarchy to them. That means, if one template type is not present, then the WordPress system will call up the next level template type. This allows developers to create themes that are fantastically detailed, which take full advantage of all of the hierarchy's available template page types, to make the setup unbelievably simple. It's possible to have a fully functioning WordPress theme that consists of no more than an index.php file!

To really leverage a theme for jQuery enhancement (not to mention help you with general WordPress troubleshooting), it's good to start with an understanding of the theme's hierarchy.

In addition to these template files, themes of course also include image files, stylesheets, and even custom template pages, and PHP code files. Essentially, you can have 14 different default page templates in your WordPress theme, not including your style.css sheet or includes such as header.php, sidebar.php, and searchform.php. You can have more template pages than that if you take advantage of WordPress' capability for individual custom page, category, and tag templates.

If you open up the default theme's directory that we've been working with, you'll see most of these template files as well as an image directory, style.css and the js directory with the custom-jquery.js file we started in Chapter 2, Working with jQuery in WordPress. The following screenshot shows you the main files in WordPress 3.0's new default theme, Twenty Ten:

[ "'I tiventyten-wp-jq ess editor-ityle-rti.css

J onecolunin-pjge.php

The next list contains the general template hierarchy rules. The absolute simplest theme you can have must contain an index.php page. If no other specific template pages exist, then index.php is the default.

You can then begin expanding your theme by adding the following pages:

archive.php trumps index.php when a category, tag, date, or author page is viewed.

home.php trumps index.php when the home page is viewed.

single.php trumps index.php when an individual post is viewed.

search.php trumps index.php when the results from a search are viewed.

4 04.php trumps index.php when the URI address finds no existing content.

page.php trumps index.php when looking at a static page.

° A custom template page, such as: page_about.php, when selected through the page's Administration panel, trumps page.php, which trumps index.php when that particular page is viewed.

category.php trumps archive.php, which then trumps index.php when a category is viewed.

° A custom category-ID page, such as: category-i2.php trumps category.php. This then trumps archive.php, which trumps index.php.

tag.php trumps archive.php. This in turn trumps index.php when a tag page is viewed.

° A custom tag-tagname page, such as: tag-reviews.php trumps tag.php. This trumps archive.php, which trumps index.php.

author.php trumps archive.php. This in turn trumps index.php, when an author page is viewed.

• date.php trumps archive.php. This trumps index.php when a date page is viewed.

• date.php trumps archive.php. This trumps index.php when a date page is viewed.

Wordpress Template Hierarchy

You can learn more about the WordPress theme template hierarchy here: http://codex.wordpress.org/Template_Hierarchy.

You can learn more about the WordPress theme template hierarchy here: http://codex.wordpress.org/Template_Hierarchy.

Make Money Blogging

Make Money Blogging

It is fine to get started on a hosted solution like Blogger.comor WordPress.com. They will allow you to learn the basics of blogging and web publishing without spending money. As soon as you nail down these basics, however, it is vital to buy your own domain name and to purchase a web hosting package with some company.

Get My Free Ebook


Post a comment