Wordpress theme: Creating a theme (Step 2)
January 8, 2007
This is part of a series of posts on how to create a Wordpress theme. See also: Step 1 and Useful Resources.
Now we have the basic layout (we could have spent a lot of time at this point working on the design), let’s turn it into a very simple Worpdress theme: an index.php file and a stylesheet, style.css.
What to put in each file:
style.css contains all the stylesheet information, I have cut and pasted this over from my original layout (see the code in the heaader). There’s also a few lines put up at the top which are used to describe your theme:
Theme Name: Summer 2007
Theme URI: http://www.cre8d-design.com
Description: A simple two-column theme.
Version: 1
Author: Rachel Cunliffe
*/
body { text-align: center; font: normal 76% Verdana, Helvetica, sans-serif;}
#container { width: 890px; text-align: left; margin: 0 auto; }
#header { }
#menu { margin-bottom: 20px; }
#content { width: 490px; float: left; margin-bottom: 20px;}
#sidebar { width: 370px; float: right; }
#footer { clear: both; }
#header, #menu, #content, #sidebar, #footer { padding: 5px; border: 1px solid #000; }
index.php is very similar to my original layout but with some minimal Wordpress code.
Use the Wordpress manual tag reference list, add tags to the HTML. I have used the following:
<?php bloginfo('name');?>in the title of the page, pulled in from your Wordpress » Options » General settings.
Why use code when you can just write the title in there? Later on, you may want different pages to have different titles and code can do this for you. Also, if you want to change your blog’s name later on, you can change it via the options page and not muck around in templates. Also, if you want to share your theme with others, you don’t want your blog name turning up everywhere!<?php bloginfo('stylesheet_url'); ?>is used for the stylesheet, instead of hard-coding in the location of it. If you share your theme with others, or move your blog, this will change automatically for you.-
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; else : endif; ?>This code tells Wordpress to display the title and content of the posts. It’s a very simple “Wordpress loop”. Wordpress will figure out what to show on different pages of the site as long as you have one of these loops in there. Basically, you can ignore understanding code in the first part of the loop and the last part - just know it needs to be there. The bit in the middle is where you get Wordpress to display your content. For my simple loop it is:
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>In other words I use two Wordpress tags, the title and the content. There are plenty of other tags on the tag reference list that you can use in here.
Here’s the index.php template:
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title><?php bloginfo(’name’); ?></title>
<link rel=”stylesheet” href=”<?php bloginfo(’stylesheet_url’); ?>” type=”text/css” media=”screen” />
</head>
<body>
<div id=”container”>
<div id=”header”>
header
</div>
<div id=”menu”>
menu
</div>
<div id=”content”>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; else : endif; ?>
</div>
<div id=”sidebar”>
sidebar
</div>
<div id=”footer”>
footer
</div>
</div>
</body>
</html>
Download the zipped theme: summer-2007.zip
Install the theme (preferably on a test site since it’s a teaching template): unzip and drop the folder into your wp-content/themes/ folder.
Next step: Expanding out the template to have more functionality (e.g. linking to each post and having comments).






Excellent!!, nice tutorial
— Oscar, January 9, 2007
Can’t wait until the next post! This is an excellent series. BTW, I think the .zip file isn’t working, unless I’m doing something wrong. –Cory
— Cory Miller, January 9, 2007
Great tutorial, this is what I was looking for,
but the link to download the zip file doesn’t work.
Generally the tutorials that i’ve seen are very complicated, whereas this looks much easier.
— Jaime, January 9, 2007
Hi - I updated the link after Cory’s comment so if you were reading the post via a feed reader, you’ll need to download it via this page.
— Rachel C, January 9, 2007
Very helpful - thank you!
Are you planning on continuing this series?
— Jörg, January 19, 2007
Hi, yes very soon - this week has been mad for me.
— Rachel C, January 19, 2007
[...] In my previous post on creating a theme, I deliberately kept things very simple in terms of both the design and the Wordpress code (”the loop”). [...]
— Wordpress theme: Creating a theme (Some side comments) | cre8d design: blog design, Wordpress themes, Drupal, Web 2.0, January 21, 2007
I found this tutorial so wonderfully helpful. I am going to link you from my blog, when I finally get it up and running.
I also know a load of people on a forum who will benefit from this tutorial so I’ll make sure they see it too.
Well done! And Thank You!!!
— Carly, March 11, 2007
Very interesting website. Keep up the outstanding work and thank you…
— slypnwam, March 11, 2007
Hello! Good Site! Thanks you! rhhetjbhuecswi
— azbrbocvux, June 25, 2007
Very awesome and simple. Thanks for this!
— shannon, June 26, 2007
Thanks for this site!
hifue.info
— wwvbmdtwxa, June 27, 2007