Theme-tastic

Time to bodge together my own theme?

It’ll probably be yellow.

Some useful links:

These are progressively more advanced topics. Some early lessons…

Theme Structure

There are really four elements of a basic theme, that are written into separate php files (representing templates). These are the header, footer, sidebar (kind of optional) and ‘the loop’. The loop is what brings content into the page on the basis of what the viewer has clicked. Each of these templates may optionally call other templates to be displayed within them.

Template pages

But, there are quite a few different ways of viewing the content – single posts, category views, tag views, search results etc. What this translates into is the need for the following template files:

  • index.php – the basic essential item, all other views fall back to using this template if the more specific ones don’t exist
  • header.php
  • footer.php
  • archive.php – essential multi-post view, I think (though falls back to index if necessary).
  • category.php – Optional, falls back to archive if unavailable.
  • tag.php – Falls back to archive if unavailable.
  • home.php – a possibility for a static homepage? In theory it doesn’t even have to call header or footer if you wanted a different start page. Optional, falls back to index.

They’re pretty much the major ones to think about, starting with index.php and then making mods for different views. Additionally, it may be necessary to think about:

  • author.php
  • date.php
  • 404.php – note need for .htaccess to get this fully working
  • search.php

And don’t forget, we’ll also need a styles.css.

Widget Complications

Widgets allow for the easy addition of new functions to the sidebar. Its essential if you’re going to share your theme. I’m not so sure its essential for a personal theme, although the very wide range of handy widgets out there (and the fact that more will come along all the time), mean that it would be preferable. So, must learn about widgetizing themes.

Primarily, the content of the sidebar should be organised with unordered lists, and include a function call (to a function defined within the theme in functions.php). functions.php itself just calls a function defined elsewhere, that presumable checks what widgets have been enabled and in what order, and grabs the necessary content.

Each widget as a unique id name for styling in CSS, but of course individually styling every widget in styles.css is going to be a pain and really defeats the easy plugin nature of widgets in the first place. Much better to set the styles for something like #sidebar.ul.li and then hope they cascade properly.

Comments are closed.