In this lesson, we will discuss WordPress Theme Structure (Hierarchy). As we discussed, Theme is a collection of files required to create a website. Theme Structure is basically, contain all the files required to build a theme. If you want to modify a theme you should know about the anatomy of a WordPress theme. A theme contains a number of individual files which performs different functions. Anatomy of a WordPress theme contains all the required files. The pages are created either using single template file or combination of multiple template files. Here we will discuss all the files contained by a WordPress theme.
Following are the important files of a WordPress theme:
When you install WordPress, there is a default theme installed. By default blog page is set as the homepage. You can set a separate static page to show your blog posts. WordPress use index.php to show your homepage. It is a required file for every theme.
The front-page.php file is used to set your site front page whether it is blog page or a separate static page. If we want to show a separate layout for the homepage we use front-page.php file.
It is use to show all comments.
The header template file usually contains your site’s document type, meta information, links to stylesheets and scripts, and other data.
The single post template is used when a visitor requests a single post.
The archive template is used when visitors request posts by category, author, or date. Note: this template will be overridden if more specific templates are present like category.php, author.php, and date.php.
page.php is used when visitors request individual pages, which are a built-in template.
category.php is used when visitors request posts by category.
tag.php is used when visitors request posts by tag.
author.php is used whenever a visitor loads an author page.
date.php is used when posts are requested by date or time.
search.php is used to display a visitor’s search results.
The attachment template is used when viewing a single attachment like an image, pdf, or other media file.
The image attachment template is a more specific version of attachment.php and is used when viewing a single image attachment. If not present, WordPress will use attachment.php instead.
The 404 template is used when WordPress cannot find a post, page, or other content that matches the visitor’s request.
functions.php is a template used by WordPress themes. It works like a plugin and gets automatically loaded in both admin and front-end pages of a WordPress site. Usually this file is used to define functions, classes, actions and filters to be used by other templates in the theme.