Creating a great theme from scratch is a challenging task. You have to define markup and behaviour, and add all of the necessary styles yourself. That being said, building from the ground up is sometimes the only thing that makes sense if you're building something really special.
Although making sure everything works correctly when you're finished will be difficult, getting started with your theme is not. There are only a few files required to get you going. After that, though, you'll be on your own as far as making sure that all of the appropriate information gets displayed.
First, create a new directory to contain your theme, and name it whatever you want. If you need help figuring out where to place your theme, see the recipe Installing and activating a theme.
Next, create the following files inside your newly-created directory:
style.css
index.php
The theme's main stylesheet (style.css) is required to contain information about the theme in a particular format. This is very important. Without this information, WordPress will not be able to correctly recognize your theme. Open style.css
and insert the following:
/* Theme Name: Your Theme Name Theme URI: http://example.com Description: Write a short description. Author: Your Name Author URI: http://example.com */
After inserting the base structure, you are free to change it to whatever you see fit. For my purposes, I've changed the code to read as follows:
/* Theme Name: WordPress Themes Cookbook Theme URI: http://plugin-developer.com/wordpress-themes-cookbook-theme/ Description: A demonstration theme for the WordPress Themes Cookbook. Author: Nick Ohrn Author URI: http://plugin-developer.com */
Now, to test that you correctly entered all the information, you need to visit the Manage Themes section of the WordPress administration panel. Open up the WordPress administration interface and click on Appearance. Scroll down, and you should see a box that contains all of the information for your newly-created theme. Given the information that I entered, my box looks like the following:
Your Manage Themes page should display the information that you entered. For more information on the different items that your style.css
file can contain, see the official WordPress documentation at http://codex.wordpress.org/Theme_Development#Theme_Style_Sheet.
WordPress themes generally contain a variety of different files to display data of different types and organizations. In addition to the required style.css
and index.php
files, you can create specially-named files that will handle certain situations.
WordPress recognizes and uses a variety of files for different situations. A full list of files and their use can be found at http://codex.wordpress.org/Theme_Development#Theme_Template_Files_List. The following list describes the most common files and the purposes for which they are used:
WordPress recognizes that a good theme will be well-organized and often has a consistent header, sidebar, footer, and comments section. As such, the following files are supported for separating those elements out, and are included with special WordPress functions:
For more information on these functions, see http://codex.wordpress.org/Theme_Development#Basic_Templates.