WordPress Templates
List of Common WordPress template files:
- Page Not Found Template (404.php)
- Archive Template (archive.php)
- Archive Index Template (archives.php)
- Author Page Template (author.php)
- Comments Template (comments.php)
- Footer Template (footer.php)
- Header Template (header.php)
- Links (links.php)
- Main Template (index.php)
- Page Template (page.php)
- Popup Comments Template (comments-popup.php)
- Post Template (single.php)
- Search Form (searchform.php)
- Search Template (search.php)
- Sidebar Template (sidebar.php)
- User Defined Templates (templatename.php)
404.php
This template will be loaded if a Page Not Found (404) error occurs on your site. There is a default 404 template included in the WordPress default theme that will be used if your theme does not include one. This site uses the default WordPress 404 template.
A very simple example for a custom 404 page from the WordPress codex follows.
<?php get_header(); ?>
<div id="content" class="narrowcolumn">
<h2 class="center">Error 404 - Not Found</h2>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
See also: Creating an error 404 page at the WordPress Codex.
archive.php
An archive template lists posts from the archive, which will be a filtered list of posts based on date criteria, such as all posts for a year or month. Usually in an archive template, excerpts of the posts are shown along with links to the full post.
archives.php
An archive index template (archives.php) is typically used to provide a list of links to archive posts, organized by year, month, etc. It differs from archive.php which will lists archive posts based on filter criteria (such as all posts for a specific year or month).
For more information on creating an archive index, see the WordPress codex here.
back to top
author.php
You can use this template to customize the profile display for authors on your blog.
For more information on author templates, see the codex article at ‘author templates‘.
back to top
comments.php
The comments template, comments.php is usually included on individual blog post pages (single.php), and is used to control the display and listing of comments on a post.
footer.php
This file is included in your other templates and holds the markup that is common to the footer of all of your pages, typically this file closes your site’s <body> and <html> tags
header.php
This file is included in your other templates and holds the markup that is common to the top of all of your pages, such as DOCTYPE declaration, <head> tags, scripts, stylesheets, etc. Usually the opening <body> tag is included here as well.
links.php
The links page template is used to display a standalone page that lists all of your WordPress links.
index.php
Required File
This is the main page of your theme, where blog posts are listed. Additionally, the way that the WordPress template hierarchy works, many of the other template files are optional, and if they aren’t present, WordPress will default to using this template.
page.php
The page template is loaded for static content pages as opposed to blog listings or posts.
comments-popup.php
This template moves the commenting ability of your theme out of the main post page and into a popup window. This was a common feature of some early blog platforms, but is rarely used now.
single.php
The single post template, single.php holds the code for showing one blog post (as opposed to static pages) and usually would be where commenting would take place on your site.
searchform.php
Many themes include a search form, that is usually included in the sidebar or footer area of the site. You can actually get the same functionality by using the search widget, which is an excellent and easy option if you don’t need to customize the form itself.
For more information on adding custom search results to your theme, check out the codex article at ‘creating a search page‘.
back to top
search.php
The search template loops over the results of a search (from searchform.php) in much the same way as posts are looped over in your main index template.
sidebar.php
This template holds the code for your site’s sidebar content area(s). This is also one of the files where WordPress widget support is generally enabled (you will also need to add code to functions.php).
templatename.php
In addition to the standard templates, you can create your own when building a theme, but instead of using a WordPress Template Tag to include the file, you can use the PHP include() function with the TEMPLATEPATH variable to do so <?php include (TEMPLATEPATH . '/templatename.php'); ?>