4R - Template Hierarchy System

Template Hierarchy System

The Template Hierarchy is a system used by Wordpress that determines which order the template files are required to display a selected webpage on a website. When a query is processed, WordPress will load a page that corresponds to the query. The query will surf through the template hierarchy to grab the output wanted.

Template Hierarchy System - Order

Some template files will over take all the others, so the higher-priority template files will be a fallback if WordPress cant find the appropriate template. Wordpress will begin a search for the selected template file when a web page is requested. If it cant find the correct one, then it will follow the hierarchy to find the next template as a solution. The break down for Template Hierarchy is categorized in seven types of pages, the PHP template files are Front page template files, Singe posts, Single pages, custom post types, search result pages, category and tag pages, and 404 errors. All with their own hierarchy.

Template Hierarchy System - File Naming Convention

It is best to create and name your files based on the relation of the page. For example, you will want to name your front page such as front-page.php. If wordpress cant find the front-page.php, then it will look for home.php and if not that, then index.php. Naming your file to the appropriate page name will allow the hierarchy to sort through and display the request webpage. Some file names will have what is known as a Slug-value or an ID. ID's are generally more easy to guess, which will make it easier for people to access or modify the resources with malicious intent. To do this you would select the page you want, find its ID, then create that file again except with the ID added in. Such as (front-page-98.php). The Slugs though, are much more difficult to guess and can provide some additional security for your website. To create a page slug, you will need to do the same thing with the ID file name, except it will be based on the "post_name" and can be accessed using "get_post_field()" function.

Summary

In conclusion, this system will rapidly determine which template file is required to display the selected web page from your site, controlling the layout of your pages.The template overall affects the look and feel of each page, post, and groups of pages. Templates ease our workload and relieves stress by the increase of efficiency in workflow.