WordPress Template Hierarchy and How to Use Them to Create a Website

WordPress Template Hierarchy and How to Use Them to Create a Website

Do you want to learn about WordPress Template Hierarchy ? Or are you a beginner and finding the WordPress template hierarchy cheat sheet? So you’re at the right place.

Here in this article, we are going to learn some of the basic template files. Which are used commonly in WordPress or used mostly by all websites. So keep with the rhythm we are going learn everything step by step.

What is WordPress template hierarchy?

wordpress template hierarchy

In simple words, WordPress template hierarchy is all about the process that runs in the backend of WordPress. When you ask to display some pages on your WordPress website. This process is super fast, it works in milliseconds. You can say this process is behind the scenes of WordPress.

Why learn WordPress Template Hierarchy?

Nowadays all WordPress websites run with templates, stylesheets, javascript, and images. They combine together and make the final show for you.

WordPress is running with the classic template hierarchy. Here you can know what template file is used for a specific area. One more thing you need to know is a template with certain filenames is allowed at some specific parts of the website.

So if you’re a WordPress developer and you want to customize the WordPress site for you or your clients. Then you need to know this basic WordPress template hierarchy. Here we listed all the necessary templates or basic templates of WordPress. In a short time, we’ll come up with an advanced template hierarchy in WordPress.

Template files for the Front page.

The front page is nothing but the home page of your website.

  • front-page.php – This file is used for the “latest posts” or a “static page”. It depends on how you set your homepage at the front page displays section of Settings > Reading.
  • home.php – If your WordPress system doesn’t have front-page.php and “latest posts” is set in the front page displays section, the WordPress system will use home.php.
  • page.php – When you set “front page” as the front page displays section Settings > Reading.
  • index.php – In your WordPress system front-page.php or home.php do not exist, at this moment WordPress use this file.

Related ArticleThe Easiest Way To Remove Sidebar From WordPress Site

Template files for the single post page.

Below files are used to display the single post page.

  • single-{post-type}-{slug}.php – If your WordPress has multiple posts and you want to show some of them separately then you can create a new template along with the post type name and post slug to display that particular post.
  • single-{post-type}.php – If you have a custom post type. And you want to display that post differently from the other post types. You can create a new template file with the post type name. Eg. single-products.php.
  • single.php – This file is the default for all single posts in WordPress.
  • singular.php – This file is also used for displaying single posts.
  • index.php – WordPress ultimately calls back to index.php.

Template files for the single page.

This list of files is used for displaying single pages in your WordPress system.

  • custom template file – For more details about the custom template file see the page template and get_page_templates().
  • page-{slug}.php – If you need to design a particular page in your website, you can create a file with the slug of that particular page. Eg. page-about.php.
  • page-{id}.php – You can display a particular page with its id. Eg. page-300.php.
  • page.php
  • singular.php
  • index.php

Template files for the category archives page.

You can display category pages in the following way.

  • category-{slug}.php – Your category’s slug is food, WordPress will search for category-food.php in your WordPress system.
  • category-{id}.php – You can display your category page using category id. Eg. category-300.php.
  • category.php
  • archive.php
  • index.php

Template files for the custom taxonomies page.

  • taxonomy-{taxonomy}-{term}.php – If your WordPress has the taxonomy custtax, and the taxonomy’s term is custterm, WordPress will call taxonomy-custtax-custterm.php.
  • taxonomy-{taxonomy}.php – If your taxonomy name were custtax, WordPress calls taxonomy-custtax.php.
  • taxonomy.php
  • archive.php
  • index.php

Template files for the custom post-type page.

  • archive-{post_type}.php – If your custom post type name is custom product, WordPress calls archive-customproduct.php.
  • archive.php
  • index.php

Template files for the search page.

Here are the template files which are used for WordPress searches.

  • search.php – This file is used for displaying the search result page by WordPress.
  • index.php

Template files for the 404 page.

Here are the template files which are used when WordPress encounters a 404 error.

  • 404.php – This file is used to display a 404 page in your WordPress.
  • index.php

As you see here the last file in all calls is index.php. WordPress falls to index.php every time.

Conclusion

In conclusion, using a WordPress template hierarchy can help you create a website quickly and easily. By understanding the different levels of hierarchy and how to use them, you will be well on your way to creating a website that looks professional and is easy to manage.

For more interesting and knowledgeable articles stay with us and you can also get HTML themes, Graphics Templates, and Creative Logo. For more details stay connected with the Geek Code Lab.

Testimonial

Very usefool plugin!
Also very good support knowledge.
Response email time, less than an hour.
Happy to buy this product!
Thanks!

ioanniskava

Woocommerce Single Product Page Customizer - Plugin

Great Support

This plugin is easy to use and does exactly what it says it will. I had one small issue and the support was terrific!

allegraportage

Woo Donations - Plugin

It works perfectly. Very useful!!!

Thanks Geek Code, the plugin works perfectly, and they were very kind to customize something for us in seconds !! Amazing!

atlasinternational

Woocommerce Single Product Page Customizer - Plugin

This a great tool for any business that needs to control their stock output. For most businesses the plugin is perfect as it is, I required a slight customisation and the team were imminent in their response time and production of the adaptation. Would recommend to anybody and will not hesitate to do business with the team again.

joseph

WooCommerce Schedule Stock Manager - Plugin

Great Functionality and Support

This plugin does not have any analogs and works great for stores that want to automate restock function in specific internals automatically

Maximus Kuzminas

WooCommerce Schedule Stock Manager - Plugin

The support was absolutely awesome – thanks a lot for the help!
The plugin works the way I expected!

sarielg

Woo Donation - Plugin

Great plugin for simple donations, works well out of the box.

It had a couple of small issues with my custom shop setup but the developer fixed them very quickly when I contacted him. It’s nice to see good support from a developer.

Happy to support this guy. Buy the license.

g-man-jones

Woo Donations - Plugin

Had an issues where the field was not properly rendering on our site. The support team already rolled out an update solving this before I even had a chance to ask.

hedgie9

Woo Donations - Plugin

Fantastic plugin!

I tried the free version of the plugin and could see that the premium version was much better. So I went and upgraded to the pro version as soon as possible.

mortenz

Woo Donations - Plugin

I needed the ability to inject OG tags into the header of individual pages. Other plugins have a lot of other functionality that I do not need.

This plugin is light and sleek and that is all it does. One thing, and it does it well.

I did have to install Classic editor alongside my existing GoodLayers setup. So far it has worked perfectly. I recommend it. I am using version 5.8.2

Tech support was very responsive, and solved my initial issue with the installation I mentioned. Thank you!

johnbroberts

Insert Script In Headers And Footers - Plugin

wanted some image under add to cart button. Done.

I wanted some image under add to cart button. Done. Nice.

wp-newyman

Woocommerce Single Product Page Customizer - Plugin

Easy and effective.

It does what it claims. I could easily added some html (text and images) before add to cart button.

lents3d

Woocommerce Single Product Page Customizer - Plugin