I actually completed one of my larger projects.

After however many weeks it ended up taking, I’ve finally finished the theme for this blog.

As far as I know from the testing I did, it functions properly. That’s no guarantee though, so if you encounter any problems don’t hesitate to mention it.

Now, I’m going to take this opportunity to talk about how much WordPress themes suck.

How much WordPress themes suck

Note: I’m going to make a lot of comparisons to SilverStripe here. Or rather, contrasts, since SilverStripe themes don’t suck.

WordPress themes are written in PHP, and here is the major problem: there is no special templating language. The theme files are literally .php files. This means that, for instance, to display the title of a post, you must write <?php the_title(); ?>.

Meanwhile, SilverStripe has its own style of template files, with unique control structures and variables. Going with the above example of displaying a title, you just need something like $Title.

Control structures get even worse. Here’s the general outline of how you display a list of posts in WordPress:

<?php if(have_posts()):
  while(have_posts()): the_post();
[markup for a single post, with chunks of PHP spread throughout]
<?php endwhile; ?>
[stuff after the posts, like pagination]
<?php endif; ?>

I didn’t even know PHP had if ... endif syntax before working with WordPress. Meanwhile, here’s how you would do something similar in SilverStripe:

<%if $Posts%>
  <% loop $Posts %>
    [markup for a single post, with instances of $var spread throughout]
  <% end_loop %>
  [stuff after the posts, like pagination]
<% end_if %>

You might be thinking, surely writing the templates in PHP makes them so much more flexible? Except that SilverStripe lets you do that too. And you need not place 20 lines of PHP in your template, because it all goes in a separate file; in fact, you can’t put 20 lines of PHP in the template file. Then you can reference the result of that by any variable name you want.

This leads into a core principle of SilverStripe: the data (database), code (PHP) and design (HTML) are all kept separate, so you don’t have complicated conditions and function calls clogging up your template.

And yet, despite how horrible it is to put PHP in your HTML, WordPress then forces you to put HTML in that PHP. I’m not kidding here. Say you want a menu, with some custom markup. How do you do it? Something like

  foreach(menu_pages() as $page) {
<li><a href="<?php echo $page['url']; ?>"><?php echo $page['title']; ?></a></li>

Nope. Apart from the fact that this doesn’t use some weird abomination of a while loop and various function calls, it also makes the menu layout too flexible.

Taking a snippet from my new theme, what you need to do is

<?php wp_nav_menu(array(
            'theme_location' => 'primary-menu',

“That’s not so bad”, you might think. But notice how the above makes no reference at all to the structure of the menu. You don’t want it to return an unordered list? Too bad! Well, okay, there’s a Walker class you can extend, but that’s a lot of hassle. Otherwise, there are only a predetermined number of aspects you can set. The classes of the outermost objects, some HTML to put before and after links (this is what I mean about putting HTML in the PHP), and that’s about it. I was lucky in this case that there was so little to adjust. Rather than modifying the structure to suit your styles, I had to adjust my stylesheet on multiple occasions (including the aforementioned menus) to suit what WordPress wanted to generate for me.

For instance, with pagination, WordPress wants to specify the active page by applying a class to a span tag. The stylesheet I started with looks for a class on the li tag with a child a instead. So of course, this means I have to adjust the stylesheet to target .pagination ul > li > span.current rather than .pagination ul > .active > a as it was doing. Why? I have no idea.

Now I could be wrong about this, but there’s not much in the way of official tutorials either. There’s basically this page and this list, and the rest you have to sort out yourself. Oh, and the default themes to use as an example.

Making this theme wasn’t painful as such, but I’m certainly not dying to do it again. Just another way I’m learning that using WordPress was a bad idea from the beginning.