Template File Tips

Here are some tips for creating WordPress template files:

Tracking Opening and Closing Tags
Template files include the use of XHTML tags and CSS references. HTML elements and CSS references can cross template files, beginning in one and ending in another. For example, the html and body HTML elements typically begin in header.php and end infooter.php. Most WordPress themes make use of HTML div elements, which can also span several files. For instance, the maindiv for the page content might start in header.php and end in either index.php or single.php. Tracking down where an HTML element begins and ends can get complicated if you are developing, designing, or modifying a Theme. Use comments to note in the template files where a large container tag opens and where it closes so you can track which div is which at the end of different sections.
Test Template Files Under Different Views
If you have made changes to the comments, sidebar, search form, or any other template file, make sure you test them using different web page views (single post, different types of archives, and pages).
Comment Deviations
If you are designing Themes for public release, keep in mind that someone who downloads your Theme will probably want to modify it slightly for their own use. So, it is helpful if you make notes in your template files where you have made changes from the logic of the Default and/or Classic Themes. It is also a good idea to add comments in your Theme’s main style file if you have style information elsewhere (such as in your header.php file or in HTML tags).
Close the Tag Door Behind You
If you start a HTML tag or div in one template file and don’t close it there, make sure you include the closing tag in another template file. The WordPress Forum gets a lot of questions about “what happened to my theme” when they remove the footer template file without closing the tags that began in the header template file. Track down your tags and make sure they are closed. (A good way to verify that this is correct is to test your single and archive page views with an HTML validator).
CSS Styles in Templates
You are free to use whatever HTML and CSS tags and styles you like in your templates. However, you are encouraged to follow the standard WordPress theme structure (see Site Architecture 1.5). This will make your Themes more understandable to your users.