The following article is about developing or designing your own WordPress Theme. If you wish to learn more about how to install and use Themes, review the documentation regarding Using Themes. This topic differs from Using Themes because it discusses the technical aspects of writing code to build your own Themes rather than how to activate Themes or where to obtain new Themes.
Why WordPress Themes
WordPress Themes are files and styles that work together to create a presentation or look for a WordPress site. Each Theme may be different, offering many choices for users to take advantage of in order to instantly change their website look. Why should you build your own WordPress Theme?
- To create your own unique WordPress site look
- To take advantage of templates, template tags, and the WordPress Loop to generate different web page results and looks.
- To provide alternative templates for specific site features, such as category pages and search result pages.
- To quickly switch between two site layouts, or to take advantage of a Theme or style switcher to allow users to change the look of your site.
- To design WordPress Theme(s) so that others may enjoy your designs through public release.
A WordPress Theme has many benefits, too.
- It separates the presentation styles and template files from the system files so the site will upgrade without drastic changes to the visual presentation of the site.
- It allows for customization of the presentation and web page results unique to that Theme.
- It allows for quick changes of the look and feel of a WordPress site.
- It takes away the need for a WordPress user to have to learn CSS, HTML, and PHP in order to have a good looking website.
Why should you build your own WordPress Theme? That's the real question.
- It's an opportunity to learn more about CSS, HTML/XHTML, and PHP.
- It's an opportunity to put your expertise with CSS, HTML/XHTML, and PHP to work.
- It's creative.
- It's fun (most of the time).
- If you release it to the public, you can feel good that you shared and gave something back to the WordPress Community (okay, bragging rights!)
Anatomy of a Theme
WordPress Themes live in subdirectories residing in wp-content/themes/. The Theme's subdirectory holds all of the Theme's style sheet files, template files, and optional functions file (functions.php), and images. For example, a Theme named "test" would probably reside in the directory wp-content/themes/test/.
WordPress includes two Themes in the download, a "Classic" and "Default" Theme. The two Themes are different and use different functions and tags to generate their web page results and looks. Examine the files carefully for these Themes to get a better idea of how to build your own Theme files.
WordPress Themes consist of three main types of files, in addition to images. One is the style sheet called style.css, which controls the presentation (look) of the web pages. The second is the optional functions file (functions.php). The other files are the template files which control the way the web page generates the information from the Database to be displayed as a web page. Let's look at these individually.
Theme Functions File
A theme can optionally use a functions file, which resides in the theme subdirectory and is named functions.php. This file basically acts like a plugin, and if it is present in the theme you are using, it is automatically loaded during WordPress initialization (both for admin pages and external pages). Suggested uses for this file:
- Define functions used in several template files of your theme
- Set up an admin screen, giving users options for colors, styles, and other aspects of your theme
The "Default" WordPress theme contains a functions.php file that defines functions and an admin screen, so you might want to use it as a model. Since functions.php basically functions as a plugin, the Function_Reference list is the best place to go for more information on what you can do with this file.
Theme Template Files
Templates are PHP source files used to generate the pages requested by visitors. Let's look at the various templates that can be defined as part of a Theme.
WordPress allows you to define separate templates for the various aspects of your weblog; however, it is not essential to have all these different template files for your blog to function fully.
Templates are chosen and generated based upon the Template Hierarchy, depending upon what templates are available in a particular Theme. As a Theme developer, you can choose the amount of customization you want to implement using templates.
For example, as an extreme case, you can use only one template file, called index.php as the template for all pages generated and displayed by the weblog. A more common use is to have different template files generate different results, to allow maximum customization.