Designing a Basic WordPress Theme

If you ever wondered how WordPress themes are put together, this tutorial will run through the very basics of a theme and hopefully wet your appetite in creating your own theme.

Before you start, think about the layout of your new theme, draw it out on a piece of paper if it helps.
For the purpose of this tutorial we are going to split our layout into a very simple grid consisting of a header, main content area, right hand side bar and a footer.

layout

 

 

 

 

 

 

 

1- Using an FTP client or file manager tool, create a sub-folder in the wp-content/themes directory in your WordPress folder and give it a theme name ie “my_theme”.

2- Use a simple text editor like notepad to create the files that relate to the layout for “my_theme”.

We are going to write 5 files to create our layout before uploading our files via FTP to our newly created “my_theme” folder –

header.php (Header area code)
index.php (This is our main area code and will specify where the other files will be allocated)
sidebar.php (Sidebar information)
footer.php (Footer area code)
style.css (This will dictate how our site will look, for example- colours, fonts, spacing etc.)

Here are the files for our layout-

header.php file

<html>
<head>
<title>my theme</title>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
</head>
<body>
<div id="wrapper">
<div id="header">
<h1>HEADER</h1>
</div>

 

index.php file

<?php get_header(); ?>
<div id="main">
<div id="content">
<h1>Main Area</h1>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<h4>Posted on <?php the_time('F jS, Y') ?></h4>
<p><?php the_content(__('(more...)')); ?></p>
<hr> <?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
<div id="delimiter">
</div>
<?php get_footer(); ?>

 

sidebar.php

<div id="sidebar">
<h2 ><?php _e('Categories'); ?></h2>
<ul >
<?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
</ul>
<h2 ><?php _e('Archives'); ?></h2>
<ul >
<?php wp_get_archives('type=monthly'); ?>
</ul>
</div>

 

footer.php

div id="footer">
<h1>FOOTER</h1>
</div>
</div>
</body>
</html>

 

style.css

body { text-align: center; }
#wrapper { display: block; border: 1px #a3a3a3 solid; width:90%; margin:0px auto; }
#header { border: 1px #a3a3a3 solid; }
#content { width: 70%; border: 1px #a3a3a3 solid; float: left; }
#sidebar { width: 27%; border: 1px #a3a3a3 solid; float: right; }
#delimiter { clear: both; }
#footer { border: 1px #a3a3a3 solid; }
.title { font-size: 12pt; font-family: verdana; font-weight: bold; }

 

These files will give us the basic layout we need. We can tweak the various css rulings to our own liking and upload posts and images to our new blog theme.