How to Build a custom WordPress theme – tutorial part 3

Structuring your WordPress theme files

The previous part of this tutorial lets you break your HTML file into several parts which then became header.php, index.php, sidebar.php, footer.php and style.css
The two most important files you must have on your wordpress theme to be detected by the wordpress framework, is the index.php and style.css, or else you cannot see your theme available as an option when you click on themes option in the admin panel.
It goes like this, when your wordpress site loads and if your theme is currently used or activated. By default, the system looks for the index.php in your theme and parses it.
Now as you notice, in your index.php file you can see lines like get_header(), get_sidebar() and etc.. These lines simply get the codes from header.php, sidebar.php and footer.php and place it together in the index.php. It works like the include() function in PHP.
That was simple; now let’s tackle about the other files you usually find on a typical wordpress theme.
Try to get some typical wordpress themes and open it up. Aside from the files I mentioned above, you can see files like page.php, single.php, 404.php, search.php, category.php and functions.php. Well some themes may have more files than these things I mentioned but I’m talking about just the typical ones.

What is the purpose of page.php?

This file is parsed instead of index.php if the requested article is a page or the article’s post type is page.

What is the purpose of single.php?

This file is parsed instead of index.php if the requested article is a post or the article’s post type is post.

What is the purpose of 404.php?

This file is parsed when a user requests a non existing page in your website. Usually it shows ERROR 404 – Page not found.

What is the purpose of search.php?

This file is parsed when a user search for a word or phrase in your website, given that the user uses the wordpress search form. So this page displays the search results.

What is the purpose of category.php?

This file is parsed when a user requests a category view. So it lists out all the posts under a particular category.

What is the purpose of functions.php?

Most wordpress developers write their own customized functions and scripts, and those codes are stored in the functions.php so that the functions will be available theme wide.
What if I don’t have those files aside from index.php and style.css?
Your theme will still work and the index.php will be used or parsed for all kinds of user requests.

So basically, it was structured that way for some purposes. Two main reasons are: First, to make debugging and tracing of codes easier and Second, Varying the display of the different kinds of user’s requests.

Leave a Reply

Your email address will not be published. Required fields are marked *