How WordPress Decides Which File to Use for Rendering the View

Nur . Posted in How-To 933 Views 3 Comments

If you have a question, “how does WordPress figure out which template file to Use for Rendering the View?”here is the answer. WordPress theme has hierarchy of template files and the index.php is the most important and required file.
If your theme doesn’t find any requested file, it moves down its hierarchy of template files to find the next most appropriate file to use.

Displaying a unique template file, you can create a file with unique name. For example, If you want to render the view for a Category #786 of your blog, create a file with this name category-785.php, and WordPress will automatically use it. Let’s take a look at the hierarchy flowchart from Digging into WordPress. In this book you will find more useful tips and tricks about developing a WordPress Theme.

Which Template File will WordPress Use

The Template Hierarchy

PAGE TYPEtries first>tries nexttries last
404404.php>index.php
SEARCHsearch.php>index.php
TAXONOMYtaxonomy-{tax}-{term}.php>taxonomy-{tax}.phptaxonomy.php>archive.php>index.php
HOMEhome.php>index.php
ATTACHMENT{mime-type}.php>attachment.phpsingle.php >index.php
SINGLEsignle-{post-type}.php>single.phpindex.php
PAGE{custome-template}.php>page-{slug}.phppage-{id}.php>page.php >index.php
Categorycategory-{slug}.php>category-{id}.phpcategory.php>archive.php>index.php
TAGtag-{slug}.php>tag-{id}.php tag.phparchive.php>index.php
AUTHORauthor-{author-nicename}.php>author-{author-id}.phpauthor.php >archive.php>index.php
DATEdate.php>archive.phpindex.php
ARCHIVEarchive.php>index.php

Reference:

Digging Into WordPress

Rockstar WordPress Designer

WordPress, Beginner to Master

Create a Universal Slider Manager in WordPress

Creating a Web Server for WordPress, Joomla or Magento

Free & Professional WordPress Security Service Free & Professional WordPress Security Service

We Love WordPress. WordPress Arena is a place for WordPress Developers and Designers, providing Tips, tricks, tools and resources to build a website or blog on WordPress. We also present The WordPress Showcase for all kind of WordPress Powered Websites.


Copyright © 2014 WP Arena All Rights Reserved

Divi WordPress Theme