1. Computing

12 Essential WordPress Theme Files in Layman's Terms

What Are the Most Important WordPress Theme Files and Why Do They Matter?


Every WordPress theme is made up of a variety of template files. These PHP (PHP: Hypertext Preprocessor) files interact with the WordPress database to output your blog in HTML format. To create a theme, only two files are required: the index.php and style.css file. Each of these files is discussed below as are ten additional files that aren't required but are very important if you want your WordPress theme to look good and work well. Additional files can be added to a WordPress theme beyond those discussed below to further customize its functionality and design, but the files listed below are the most common and useful.

Even if you're not a WordPress theme developer or designer, if you use the self-hosted application from WordPress.org for your blog, there may come a time when you want to make changes to the files and tweak your blog's design or functionality. It's a lot easier to find the features you want to edit if you know which file those features are likely to be coded.

1. index.php

The index.php file is used to display your posts on a page of your blog. For example, your blog's home page (if it shows your most recent posts), archives page, search results, tags page, and categories page will all be displayed based on the formatting defined in the index.php file unless an individual PHP file has been created for any of those specific pages. For example, if an archives.php file is included within the WordPress theme files, it will override the index.php file when a category page, author page, or date page is displayed.

2. style.css

The style.css file is known as your blog's stylesheet. It is coded using Cascading Style Sheets (CSS) and identifies all of the visual design elements of your blog such as colors, fonts, bullet styles, and how big your header, footer, sidebar, and so on will be.

3. header.php

The header.php file is used to display your blog's header at the top of any page of your blog. For example, in order to display your blog's header at the top of your archive pages, the archive.php file has to include special code to call up the header.php file and display it as part of the archive page.

4. footer.php

The footer.php file is used to display your blog's footer on any page of your blog. It works similarly to the header.php file. For example, in order to display your blog's footer at the bottom of your archive pages, the archive.php file has to include special code to call up the footer.php file and display the footer as part of the archive page.

5. sidebar.php

The sidebar.php file works just like the header.php and footer.php files. Enter code into your page or archives.php files to call up your sidebar, and the sidebar will display on those pages. You can create multiple sidebar files if you want to show different sidebars on different pages of your blog. For example, you might want to show one sidebar on pages and a different sidebar on post pages.

6. home.php

The home.php file is used as the front page of your blog. However, if you use a static front page for your blog that does not include the typical list of your latest posts, the home.php file becomes the template for the page that displays your latest posts, and a separate front-page.php file is used for your blog's static front page.

7. page.php

The page.php file is used for individual pages on your blog. You can create multiple page.php files.

8. single.php

The single.php file is used for single blog post pages. You can create multiple PHP files for different types of posts.

9. archive.php

The archive.php file is used when a category, author, or date page is displayed if there are not separate PHP files created for each type of posts archive (i.e., category.php, author.php, date.php). If one of those PHP files is included in the theme, it overrides the archive.php file. Some themes also include a tags.php file (or you can create one), which is used when tags are queried and would override the archive.php file.

10. search.php

The search.php file is used to display search results when visitors conduct keyword searches on your blog.

11. comments.php

The comments.php file is used to display the comment form at the end of your blog posts as well as the actual comments submitted by visitors.

12. functions.php

The functions.php file is used to define specific functionality that is used in multiple places within your theme. Rather than adding code for a function to multiple PHP files, you can add it to the functions.php file and have the other PHP files call up the functions.php file. This is a great time-saver when you first add the functionality and when you edit it in the future.

©2014 About.com. All rights reserved.