 Hey there and welcome to Learn WordPress. In this tutorial you're going to learn about the WordPress template hierarchy and why it's important to know if you're developing a WordPress theme. In this video we will cover a brief overview of the WordPress template hierarchy, how the template hierarchy works, and the template types that make up the template hierarchy. Every WordPress theme is primarily made up of template files. Templates are what WordPress uses to generate the web pages on your WordPress site. For example, whenever a WordPress post is displayed in the browser, the template to render posts is used. Similarly, whenever a page is displayed, the template to register pages is used. However, a typical WordPress site doesn't just have one content type. It might have other things like a post archive list, a 404 page, and a search results page. There might also be custom content types that need to be rendered differently, like a list of products or an archive of posts by a specific author. So how does WordPress know which templates to use and when? This is where the WordPress template hierarchy comes in. The template hierarchy is the system that WordPress uses to determine which template files should be used to render individual pages. When a user requests a WordPress page, it's usually done by means of a permalink. Here is an example of the permalink to the archive page for a specific author. However, the permalink is actually translated by the web server to something called a query string. The query string is what WordPress uses to determine what content to display. So the author archive page query string for the above permalink would look like this. WordPress also uses the query string to decide which template or set of template should be used to display the content for the page. When the WordPress page execution runs the query, it follows a process to search down through the template hierarchy until it finds a matching template file for the content. Let's look at the above example of the author archive page and follow the process. Let's say you have an author with a slug or nickname of John Doe, which has an ID of three stored in the database. On your site, you have a link to the author's archive list, which is a list of all posts by that author. The URL for this list would typically look like this. When WordPress translates that permalink into a query string and looks for the template to use to render the author archive list, it will follow the following process determined by the template hierarchy. First, it will look for a template with a file name author-John Doe. Then it will look for a template with a file name author-3. Then it will look for a template with a file name author-archive. Then archive. And finally, it'll look for index. If it finds any of these templates in the active theme, it will use that to render the author archive list. In classic themes, your templates are PHP files with a PHP extension. In blocks themes, they are HTML files with an HTML extension. Regardless of the type of file, the template files must match the naming convention of the template hierarchy in order for WordPress to be able to find and use the right template. The visual overview of the WordPress template hierarchy is a good way to understand the system. On the far right, you'll notice there are a series of primary templates in purple. These templates are the core templates that every WordPress theme must have. This is because these are the default fallback templates that the template hierarchy will rely on if none of the templates higher up exist. As you can see, the archive, single, page, home, 404 and search templates are the fallbacks for any other template higher up, while the index template is the ultimate fallback template. If you're creating a WordPress theme, it's recommended to include at least these seven primary templates. Next, there are the secondary templates in green. These are typically extensions of their primary counterparts, but created for specific purposes. For example, author is an extension of archive, but for a specific archive of posts by an author. Higher up, you have the variable templates in orange. These are templates that are different depending on the part of their file name that is available. So for example, you could have author hyphen John Doe template for all posts by John Doe, and then an author hyphen Jane Doe template for all posts by Jane Doe. The two variable templates available for this would be the author ID template and the author nice name template, where ID and nice name are the variable parts. Finally, the visual overview also shows the page types in dark gray. Each type of page will have one or more templates along the hierarchy, all the way back down to the index template. And that is a quick overview of the WordPress template hierarchy. For more information on how the template hierarchy works, including the visual overview and a detailed breakdown of each template along the hierarchy, visit the template hierarchy documentation, which is in the theme developer handbook on WordPress.org and a theme basics. Happy coding!