As we mentioned in the introduction, A theme is a collection of files contained within a folder.
A theme can contain several files, but All themes must have the following files.
- Main Index Template [index.php]
- Stylesheet [style.css]
Lets learn about the core files [Main Index Template and Stylesheet] first, and later we can jump into other files within a theme.
1.Main Index Template [index.php]
As the name suggests, this is the main file in any theme. This file contains the PHP code that defines What to Show when a browser is asking for a page in your wordpress site. It has the necessary code to pull posts / pages from the database and it can also make a call to predefined wordpress functions to display links for category, archives, etc.
This file contains the CSS statements that defines How to Show it in the browser.
The top portion of this file has a few statements to introduce the theme to the underlying WordPress. Basically it gives some information like the theme name, its version, description, its author name etc.
WordPress displays that information on the themes page.
ok. Now you understood about the 2 core files of any wordpress theme, one that defines what to show and the other one that defines how to show. Thats fair enough.
but I see more than these 2 files, in any theme [both the default themes and the ones downloaded from the internet]. We will come to that in just a moment.
Splitting up the index.php
After a lot of thinking and analysis, they found that each page you see in the site has these four parts in general.
so index.php contains the necessary code for displaying the header, the content, the sidebar and the footer.
In most cases, the “header”, “sidebar” and the “footer” do not change as much as the “content” area. So the “header”, “sidebar” and the “footer” are all separated into their own files known as header.php, sidebar.php and footer.php respectively.
index.php will just have the portion of code that deals with “the content”, while just including header, sidebar and the footer in appropriate places.
Open up any theme’s index.php, you will see get_header(), get_sidebar() and get_footer().These are the methods WordPress provides that will take care of including header.php, sidebar.php and footer.php from within the theme’s folder.
So, now we have more files in the theme folder, but they are much easier to manage now.
Cool. Now that you know about the basic building blocks of a theme. we will talk about each one of them in the upcoming parts.
Now go have a cup of coffee and relax ! 🙂