Monday, August 27, 2012

WordPress Template Hierarchy – Template hierarchy in details

Personalizando WordPress 1.5

Personalizando WordPress 1.5 (Photo credit: juanpol)



WordPress is programmed to interact with your theme files in presenting content to different sections in your site. WordPress core developers devises a template hierarchy to systematize the management of templates.


Think of template hierarchy as an order of importance. Each of the different content section of a WordPress website has its own canonical/official or standard template. For example, single.php is the canonical template when generating blog post content while category.php is the canonical template of WordPress categories. Other canonical templates are summarized on the previous section.


WordPress would be looking for this canonical template first in your theme directory before other templates would be considered.


Below are some example of the most important hierarchies applicable to most WordPress themes (the first one is the canonical template):



  1. Generating blog post:

    • single.php

    • index.php



  2. Displaying home page content:

    • home.php

    • index.php



  3. WordPress page content:

    • page.php

    • index.php



  4. Category content:

    • category.php

    • archive.php

    • index.php



  5. Displaying tags:

    • tag.php

    • archive.php

    • index.php



  6. Author content:

    • author.php

    • archive.php

    • index.php



  7. Search results:

    • search.php

    • index.php



  8. Template to use if the URL is not found (404):

    • 404.php

    • index.php




How to use and understand them?


As discussed previously, WordPress will be looking first for the canonical/official template for displaying content in a specific section of your WordPress site. If its not available (probably because theme developers didn’t use it), WordPress will be looking for the second template file under its hierarchy.


For example, supposing author.php is not available in your themes, WordPress will be using archive.php since this is the second template in the hierarchy.


If archive.php is still not available, it will look for index.php that is the third and the last template in the hierarchy. If still not found; error or a blank page will be returned to the browser.


Another example is when category.php is not available or used by your themes, WordPress will look for archive.php to display category content. It is because archive.php is #2 in the template hierarchy (based on the above list). However if archive.php is also not available, WordPress will look for index.php and use it.


If you are examining the above hierarchies, you will notice that index.php can be used to generate any types of content in your WordPress site (regardless if it is a post, page, tag, categories, etc.) only if all canonical templates are missing. However, this is not a common practice and all themes do have its own specific templates for generating content in different sections of your WordPress site.


This is a part of WordPress Template Hierarchy tutorial.



The post WordPress Template Hierarchy – Template hierarchy in details appeared first on Tutorial Mini.


Related posts:



  1. WordPress Template Hierarchy

  2. The Anatomy of a WordPress Theme – Dynamic Content

  3. The Anatomy of a WordPress Theme – Theme Location






via Tutorial Mini http://tutorialmini.com/wordpress-template-hierarchy-template-hierarchy-in-details/

No comments:

Post a Comment