Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Wordpres theme template hierarchy

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 306
    Comment on it

    In wp, pages are join together from different theme template files. Each & every template file of wp represents section of the web page, and all together they render all of the content of individual web pages, pulled from the wp admin. However, which theme template file is actually selected is based on a wp robust hierarchy(please check attachment), with a naming convention at its root. In this hierarchy, a default template is replaced by template files that are more specific.


    Example: Suppose user hit this page http://example.com/author/devendra. wp will search for the template called author-devendra.php. If that file doesn't exist in the theme, then it looks for author.php. then it next looks for archive.php. Finally, if this is not found in the theme, it uses index.php to render the page. Each time a user visits your page, WordPress trace the template hierarchy until it finds a right template file that matches the request. And this has everything to do with how these files are named.


    Conclusion: WordPress templates works together to generate the web pages on your WordPress site. some basic templates like header, sidebar & footer template files are used on all the web pages, while others like author, archive, category are used only under specific conditions.


    Page Hierarchy:
    1. page-{slug}.php
    2. page-{id}.php
    Lets say user hit 'contact' page,
    If the page slug is contact, WordPress will look to render "page-contact.php". if that file doesn't exist in wp theme folder then it will check for "page-{id}.php". here the "id" is the id of contact page. if the page ID of contact page is 6, WordPress will look to use page-6.php

    Wordpres theme template hierarchy

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: