When you publish a post on WordPress, the content is stored in the database. For display purposes, WordPress uses the content from the database and the layout from the themes. A theme has multiple files for different parts of the webpage such as header, footer, content part etc.
The loading of the theme files while displaying content on your WordPress blog is based on a “hierarchy”.
The hierarchy deals with 5 main page types:
- Main content – The hierarchy for this includes:
- Index.php – for content type basically the root page
- 404.php – for 404 errors that occurs, when the requested page is not found
- search.php – for search results, whenver there is a search query request from the user
- Archives – Templates for listing the blog posts under categories and tags are included here
- Pages – Templates for specific content on static pages, the WordPress blog pages
- Posts – Templates for posts that are customized, the WordPress blog posts
- Additional files – This includes the templates for blog header, menu, footer design and sidebar widgets etc.
For example, for a static homepage, the file – ‘front-page.php’ will be used. No other file will be considered unless the front-page.php cannot be found. For a search page, the file – ‘search.php’ will be considered.
If you use a child theme and the child theme has all theme files they will be used. If the child theme does not have a theme file, then the parent’s theme file will be used. Basically, the child theme files takes priority over parent theme files.