Creating a WordPress Theme HTML Structure

Quality Themes for $15 Now we’re starting to get into the real meat of WordPress Theme development: coding the HTML structure.

The Goals of Any HTML Structure

When coding a web site you should have 2 goals in mind: lean code and meaningful code. That is, using as little markup (HTML tags) as possible and making sure that the markup is meaningful by using semantic class and ID names that refer to their content, not how they “look” (class=”widget-area” instead of class=”sidebar-left”).

Now, when coding a WordPress Theme (or any template for any Content Management System) a balance is going to have to be struck between lean markup, with very little structure, and what’s called Divitis; including too many unnecessary div elements in your code. In other words, too much meaningless structure.

You’ve probably seen the div tag before if you’ve looked at the code for a website or any WordPress Theme. Think of them as containers for HTML code—containers that are very handy for manipulating HTML code with CSS. Obviously we’re going to have some. But we don’t want too many or ones without meaning. And we want enough structure—using the div tag—that we can reuse our code for multiple blog and site layouts. We want to code something we can come back to and use again.

The HTML Structure for Your WordPress Theme

Let’s take a look at the HTML structure we’ll be using for the body of our WordPress Theme.




<html>
<head>
</head>
<body>
<div id="wrapper" class="hfeed">
    <div id="header">
        <div id="masthead">
         
            <div id="branding">
            </div><!-- #branding -->
             
            <div id="access">
            </div><!-- #access -->
             
        </div><!-- #masthead -->   
    </div><!-- #header -->
     
    <div id="main">
        <div id="container">
         
            <div id="content">
            </div><!-- #content -->
             
        </div><!-- #container -->
         
        <div id="primary" class="widget-area">
        </div><!-- #primary .widget-area -->
         
        <div id="secondary" class="widget-area">
        </div><!-- #secondary -->
    </div><!-- #main -->
     
    <div id="footer">
        <div id="colophon">
         
            <div id="site-info">
            </div><!-- #site-info -->
             
        </div><!-- #colophon -->
    </div><!-- #footer -->
</div><!-- #wrapper -->
</body>
</html>

A Quick Tour Through Your WordPress Theme HTML

Firstly, the class attribute on the wrapper, hfeed. hfeed is part of the hatom Microformat schema. In plain English, this means that adding that hfeed class to our page tells any machines reading our site (like search-engine bots or some other service) that our site publishes syndicated content, like blog posts. You’ll be seeing a lot of class names like this as we go along.

Looking at the div structure for the header and footer you’ve probably noticed what I’ll call an inner-outer structure. This is one of the few places (hopefully) that our structure could potentially be accused of Divitis. Potentially. Borrowing class names from the publishing world (WordPress makes us content publishers, right), I’ve tried to add some meaning to the markup that will be resting in these containers. Markup that we’ll be adding in this tutorial series and markup that will may be added in the future. Plus, to accomplish certain layouts, we’ll need this markup structure. It’s better to add it now and do it right.

In the main area of our HTML you’ll notice that we have 2 widget areas that come after our content area. And you may also have noticed that our content rests inside a container div. These points are key. This not only let’s our main content come before the sidebars in the eyes of search engines (and screen readers) but by using a CSS technique involving negative margins we can make this into a 1, 2, or 3 column theme with only a few lines of CSS.

This HTML structure is going to future-proof your WordPress Theme and give you the opportunity to do powerful stuff with CSS. It’s a good one.


        WordPress Theme Tutorial Introduction
        Theme Development Tools
        Creating a Theme HTML Structure
        Template and Directory Structure
        The Header Template
        The Index Template
        The Single Post, Post Attachment, & 404 Templates
        The Comments Template
        The Search Template & The Page Template
        The Archive, Author, Category & Tags Template
        The Sidebar Template
        Reset-Rebuild Theme CSS & Define Your Layouts 

WordPress Theme Development Tools

Quality Themes for $15 Before building any WordPress Theme we’re going to need to get our development tools in place. In this post, we’ll run through the best of the best and build ourselves a cross-platform WordPress Theme test environment that would do a professional Theme developer proud.

A Local Test Server: XAMP or MAMP

The best place to develop your custom WordPress Theme is off the web, on your home computer. To do that though you’ll need to turn your computer into a “local server”, essentially approximating the program suite on a regular web server (Apache, MySQL and PHP). This means you can install WordPress on your home computer.
Installing these separate server programs can be technically challenging but luckily for us there are a couple of free programs that will install and manage all this for us.
If you’re on a Windows computer you’ll want to try out XAMP.
If you’re running a Mac you’ll want to download MAMP. It’s what I use and it does the trick.

WordPress

Of course, we’ll need to download the latest version of WordPress and get it correctly installed on your local test server.
If you’re using XAMP follow these instruction for installing WordPress on your local test server.
If you’re using MAMP follow these instructions for installing WordPress on your local test server.

Dummy Content

Your WordPress installation is going to need some sample, or dummy, content. Something to theme. In your WordPress admin navigate to Tools > Import and choose WordPress from the list of options. Now we only need a WXR post data file to import.
There are a couple options:
Each of these test data sets has their pluses and minuses. One thing I like to do is import all the dummy content I can. Everything. That way nothing gets missed. When you think you’re done your theme, use the post navigation to browse through each post. Check out the archives for the month and year and category. With robust dummy content it’ll be easy to see if something’s amiss.

A Text Editor

You won’t need any special graphics software for creating WordPress Themes just a plain old text editor. But some are better than others, of course.
For Windows, you can try Notepad++. It’s free and open-source, and comes recommended by Lifehacker.
For the Mac, I recommend Text Wrangler.

Firefox

Of course, you can use any browser for web development but the one I recommend is Firefox. Especially with the following 2 add-ons that will make your life a whole lot easier when it comes to developing with WordPress.
The Web Developer Add-on for Firefox adds a toolbar that gives you a whole host of options for inspecting and debugging your code, from disabling all CSS styles to validating local HTML (that’s the stuff happening on the browser screen of your test server).
The Firebug Add-on for Firefox is indispensable. With Firebug enabled you can click on any element in your browser window and see—in a window at the bottom of the screen—how it looks in the source code and how it’s being affected by CSS.

HTML and CSS

I won’t lie, a passing familiarity with basic HTML and CSS will help you out. I recommend reading through the HTML Dog HTML Beginner Tutorial and the HTML Dog CSS Beginner Tutorial . Reading through these two tutorials is completely optional but it won’t hurt and will help you grasp some basic concepts.

PHP

But what about PHP? Don’t you need to know PHP to create a WordPress Theme? Well, yes, you do. But I’ll be teaching you enough to be dangerous with a WordPress Theme as we go along. If you want to be a keener—always recommended—you can start reading through PHP 101: PHP for the Absolute Beginner. Again, completely optional. You’ll only need to pick up the basic concepts really.

        WordPress Theme Tutorial Introduction
        Theme Development Tools
        Creating a Theme HTML Structure
        Template and Directory Structure
        The Header Template
        The Index Template
        The Single Post, Post Attachment, & 404 Templates
        The Comments Template
        The Search Template & The Page Template
        The Archive, Author, Category & Tags Template
        The Sidebar Template
        Reset-Rebuild Theme CSS & Define Your Layouts 

How To Create a WordPress Theme-The Best Tutorial and Guide

Quality Themes for $15

 This wordpress Theme Tutorial is the best guide to learn how to create or build a powerful and up-to-date wordpress theme from scratch. You will learn everything you need on how to create a wordpress theme as we proceed with the tutorial.
Your newly created wordpress theme will feature
  • All the search-engine optimization you’ll really need
  • Including google-supported Microformat markup
  • Valid and logical semantic markup structure than can be used to create ANY layout
  • Smart default CSS layouts
  • Dynamic Body, post and comment classes
  • Separated trackbacks and threaded comments
  • 2 widget areas coded to disappear when they’re empty
  • And all the typical WordPress stuff you expect from a theme
I think thats good as far as any WordPress Theme is concerned. The guide will help you to learn everything you want about Wordpress Theme. The impressive thing is that you can use your newly created wordpress theme for your own website or commercial puropses. The guide is free to use. You will be free to use the source code.

How to create WordPress Theme Tutorial Table of Contents

Follow the following simple steps to create a powerful WordPress Theme from scratch. Code yourself to get an awesome theme.

  •     WordPress Theme Tutorial Introduction
  •     Theme Development Tools
  •     Creating a Theme HTML Structure
  •     Template and Directory Structure
  •     The Header Template
  •     The Index Template
  •     The Single Post, Post Attachment, & 404 Templates
  •     The Comments Template
  •     The Search Template & The Page Template
  •     The Archive, Author, Category & Tags Template
  •     The Sidebar Template
  •     Reset-Rebuild Theme CSS & Define Your Layouts