How WordPress Decides Which File to Use for Rendering the View

Nur . Posted in How-To 418 Views

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 TYPE tries first > tries next tries last
404 404.php > index.php
SEARCH search.php > index.php
TAXONOMY taxonomy-{tax}-{term}.php > taxonomy-{tax}.php taxonomy.php> archive.php> index.php
HOME home.php > index.php
ATTACHMENT {mime-type}.php > attachment.php single.php > index.php
SINGLE signle-{post-type}.php > single.php index.php
PAGE {custome-template}.php > page-{slug}.php page-{id}.php> page.php > index.php
Category category-{slug}.php > category-{id}.php category.php> archive.php> index.php
TAG tag-{slug}.php > tag-{id}.php tag.php archive.php> index.php
AUTHOR author-{author-nicename}.php > author-{author-id}.php author.php > archive.php> index.php
DATE date.php > archive.php index.php
ARCHIVE archive.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

Nur

I am a Wordpress, Website Developer and Designer, creator @ WP Arena, Provide Free WordPress consultation and can help to install WordPress in a secure way to small businesses and bloggers.

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.

Recent Comments

Tink Seagraves

|

Seems to have a little crush on G-Dub!