WordPress Themes come with multiple templates for displaying pages,posts,archives etc.
Each page type can, and often does have, its own template files.
Below is a screen shot of the 2012 theme folder. Notice the files archive.php, author.php, category.php.
These are the template files for displaying archive, author info and category pages.
The files index.php, and page.php (circled in red) are the default templates for displaying posts and pages.
Web Page Structure
The web page layout will change depending on the theme. That is; some pages will have a single column, some two columns, some will have the content on the left others the content will be on the right etc .
Regardless of this WordPress considers all web page to consist of 4 distinct blocks, as shown in the diagram below:
If we look at any one of the template files we will see this structure. Here is the code from the archive.php (2012 theme).
The function calls get_header(), ,get_sidebar(), get_footer(), are defined in wp-includes/general-template.php file
They load the header.php ,sidebar.php and footer.php template files.
These files are located in the current theme directory (screen shot above).
Which template is used when displaying a page/page is determined by the template hierarchy.
The WordPress Codex has a good description of how the hierarchy works. But the simple version is:
Arhive.php is the template for archive pages, category.php is the template for category pages and so on.
Page.php is used for pages (not posts) unless another template has been defined and selected.
The screen shot below taken from the WordPress page editor shows several page templates are available for a page.
These additional page templates may come as part of the theme or you can create your own custom templates.
index.php is used to display the main blog page. You should note that this may or may not be the home or front page.
index.php is also used if WordPress cannot determine which other template it should use i.e it is the default template for all pages and posts unless they have a more specific template defined.
Home and Front Page Templates
WordPress was originally designed as a blog and so the traditional home page was a list of blog posts.
The home page and the front page were the same
However with static front pages (introduced in 2.1) the front page can be a static page, and not a list of blog posts.
If this is the case then the page.php or other template file will be used to display the front page.
The page that displays the list of blog posts will use the index.php template file .
Test it Yourself
If you want to see which template is being used to display a page just add the following code to the footer.php file in the theme you are using.
When you view a page on the site you should see the following at the bottom of the page.
References and Notes:
Notes: The logic for determining which template is going to be used is found in the files template-loader.php and template.php files, which are located in the /wp-includes directory.
A single post page will usually use the single.php template (if available).
You cannot change the template of a post from the WordPress editor like you can with a page.
Related Articles and Resources:
- Beginners Guide to the Load process
- function reference is_home() – good overview of static front pages and home pages as used by WordPress.
- Template hierarchy WordPress Codex