KillerSites Blog

Creating WordPress Themes from scratch.

May 14, 2008

wordpress screenshot

This first article is meant to give you a global picture about creating WordPress themes. Let’s start by answering a few common questions.

Do you need to know PHP to create or edit WordPress themes?

The short answer is no. It would help to know some PHP but many theme designers don’t, and they do just fine.

Do you need to understand MySQL to create or edit WordPress themes?

Again, no. Mysql is the database that drives WordPress and is a key component … nonetheless, it has no impact on creating themes. So don’t worry about it.

What do you need to know in order to be able to edit or create a WordPress theme?

I would say that you need to know three basic things:

  1. HTML/XHTML
  2. CSS
  3. The WordPress page hierarchy and behavior.

I think the first two are obvious, but the last needs some more explaining.

What is the WordPress page hierarchy and behavior?

In a nutshell: WordPress has a hierarchy of template pages that it follows whenever someone request a post.

… If WordPress can’t find a certain template, it will fall back and use the default (index.php) to display the information. If this doesn’t make sense, please check out the diagram below … it should help:

wordpress-page-hierarchy

For example:

Let’s say a visitor uses the built-in WordPress search capability. To display the search results, the WordPress engine will first try to load the ‘search.php’ template page. If it can’t find it, WordPress will use the ‘index.php’ instead.

So what the diagram shows you, is that the index.php page is kinda the ‘master template’ … and if any of the other templates can’t be found, the WordPress engine can always use index.php.

… I hope this makes a little sense.

Why do you have to understand this?

Now that we understand how the WordPress engine looks for page templates in a theme, we now know what page templates we need to build.

Does a theme have to include ALL the template pages?

If it isn’t already obvious, you can get away with creating a theme with only one template page: index.php.

In this ultra simple theme, all your pages would be exactly the same since the WordPress engine would be using the same template (index.php) for all the page types. That said, you will also need the default ‘styles.css’ file for all your CSS code.

So the bare minimum theme must only have two files:

  • index.php
  • styles.css

To customize all the possible pages that WordPress can display, you would need to include all these page templates:

* style.css
* index.php
* home.php
* single.php
* page.php
* archive.php
* category.php
* search.php
* 404.php
* comments.php
* comments-popup.php
* author.php
* date.php

Conclusion

The point of this article was to give you a global understanding of what it takes to create themes in WordPress.

If you guys want to learn more about creating themes for WordPress … let me know.

Thanks,

Stefan Mischook

www.killersites.com
www.killerphp.com