[wp-hackers] Theme structure
dougal at gunters.org
Thu Jun 12 12:50:17 GMT 2008
Alan Baljeu wrote:
> I'm working on building an interactive theme editor. The idea is that the editor would enable definition of various layouts, and support styling. The goal is to enable relative novices to design their own theme, then if they find cool stuff somewhere and put it in with a text editor, then the theme editor will still be able to work with the modified files. Obviously, not every change can be accommodated, but I'm thinking to cover certain "normal" changes.
> At this point, I'm just working out the concept.
> First though, I want to understand better the structure and conventions of a theme. Obviously, WP generates HTML files using PHP, but in general people could do all kinds of wacky things in PHP. I was wondering if there are solid standards about how a page comes together. For example, are functions usually expected to create balanced HTML, or is it common to produce unbalanced code that must be closed off by another function? For example, get_header() generates HTML which is incomplete without calling get_footer(). In cases like this, I could just pair off the two elements, and allow arbitrary stuff to be added between..
> How much can a not-totally-stupid editor attempt to understand the structure of a document? What are the gotchas to watch out for?
Obviously, the Codex is one of the best places to look for information
on building templates. It contains information about the "standard"
template structure, and how the files are broken up (header, footer,
sidebar, index, single, page, etc.). I know somebody else already
mentioned Sandbox, but I'll put in a second vote for looking to it as a
good example of a "blank slate" template, ready to be shaped by CSS. I
realize you've got more than that in mind, but it's still a good theme
to learn from.
I would also recommend checking out the "One True Layout" article for
tips on how to get some of the flexibility you want just with CSS, and
not having to resort to rearranging the HTML. Another framework for this
is YUI Grids, which achieves a remarkable amount of layout
flexibility simply by changing which classes you use on key HTML
elements. They also have an online "builder" app, similar to (but
more limited in scope) what you have in mind, I think.
Oh, and to answer another question, WP functions do their best to output
valid XHTML snippets. Exactly what they output depends on the context of
how it's normally used. For example, most of the list functions (e.g.,
wp_list_pages(), wp_get_archives(), etc) will output <li> tags, and
expect that the wrapping <ul> or <ol> is already in the template. Again,
look at existing themes for examples.
Dougal Campbell <dougal at gunters.org>
More information about the wp-hackers