When someone lands on your WordPress website the template hierarchy tells WordPress which template files within a theme to use at any given time to determine how that current page should look. The template hierarchy exists to make it easy for someone to customize their WordPress site. By utilizing template hierarchy when creating a theme, your front page, category pages, posts, and individual pages can all have their own unique look and feel. It works by WordPress using an order called a query string that decides which template or set of templates to build. WordPress searches through an ordered template hierarchy system until it finds the right files to build a page. If a specific file can't be found for any reason, WordPress looks for the next best alternative to render.
WordPress lets you use multiple page types, depending on what you want to publish. There are seven main categories you can use: Front Page, Single Posts, Single Pages, Custom Post Pages, Search Results Pages, Category and Tag Pages, and 404 Error Pages. Each of those seven types have their own custom hierarchy that uses their own specific set of templates. To show an example of this, the "Front Page" is the first stop most users make when visiting your website. WordPress will look for these three template files in order to display your front page: front-page.php, home.php, and then index.php. If WordPress cannot find the first template file, it goes down the list and loads the last one, index.php, if none of the others can be found and utilized. In all of the 7 page types in the template hierarchy system, index.php is the last stop that WordPress makes down the template decision tree if higher ranking files cannot be found.
In WordPress a naming convention must be followed when creating your template theme pages as it follows a specific pattern to help WordPress identify which one to use. Additionally, you can create templates for specific slugs and IDs as well. Below is a list of the naming convention for theme files.
WordPress uses a template hierarchy system to determine how specific pages of your WordPress site should look. There are 7 different types of pages on a WordPress site, and with the template hierarchy system, you can customize those to look different from pages that display other types of content on your website. Each of those 7 types of pages follow their own naming convention patterns. If a theme file cannot be found, WordPress goes down the hierarchy until it finds a file to load into the theme before defaulting to index.php. Index.php is the default file at the bottom of the hierarchy for all of the 7 specific page types.