Tutorial: How To Make A Theme/Layout For WordPress
November 13th, 2010 by Aashni13 CommentsHere is a tutorial showing you how to make a layout that is WordPress friendly. Create a new folder with the name of your layout. For this example, I’m making a “Heart Broken” layout with Blair Waldorf from Gossip Girls. I’m calling my file “hbb” – “heart broken blair”. You can call your file anything you’d like.
*Note that this layout does not include a sidebar, but a navigation menu at the top of the page.
Step 1: Create the Layout Images
Personally, I like making all my images first, then working with widths and sizes etc. I have four standard images that I make everytime, as you can see in the screenshot below.

1 – The header for your layout – This should be attractive, and should have your site name, or some text on it. The header should also have the background color, and the top part of the content area.
2 – The repeating pattern for the body of your layout – The background of the body of my layouts, where the content goes, is a simple repeating design. Once you’ve made your header use the selection tool, select the portion of the header that is the top of the content (thought don’t copy the top of the content area), and this is normally fine. I say that it’s normally fine because you may have added fancy designs in your header that spill over onto the top of the content section. Be careful in what you select in this case, as it will repeat down your page.
3 – The footer for your layout – This should provide a clear “end” to the page, so that users with slow internet don’t wait for more information to load. Most people have their credits here as well.
4 – The background color – Some browsers interpret hexadecimal colors differently, resulting in your layouts background being different to the main background of the page. To avoid this problem, just copy a small square of the main background color from the header, and save it as the layouts color or main background.
Save all the images in a folder called “images” inside your main folder.
Step 2: Create the Generic Layout Code
In this step, you will code the layout the same way you code any other layout. I strongly suggest using div’s in your layout, over tables, as Div’s are easier to integrate in a WordPress layout, with fewer mistakes. It also allows for a lot more flexibility in the layout. I personally prefer using Dreamweaver to code my layouts, however you can use textedit, notepad, anything.

Create a main container div around your entire layout. This will contain everything you do in your layout, as can be seen by the container, or blue line.
Not split your layout into a header, content and footer area.
The header contains your header image, as well as the navigation links that appear at the top of the page.
The content contains your blog posts, resources, contents, photos, poems or anything else that you will have on your site.
The footer ends the page, and contains copyright information. You usually copyright your site to youself if your site was entirely made by you. You can also credit people who inspired your site, or helped with your layout.

Save this code in your “hbb” file, and name it as a generic or basic layout for your theme. For example, “hbb_generic”.
Make sure you test your layout in as many different browsers as you can. The main browsers to test with are Google Chrome, Firefox, Safari and Internet Explorer.
To code your layout, split it up into three (or four, if you have a sidebar) areas.

Step 3: WordPressing – CSS
Now comes for the trickier parts of creating your WordPress theme. WordPress uses PHP Includes to include different parts of your code into the theme. Have your hbb_generic file open, but make sure you don’t edit anything in this file. Now copy ALL the css text in the file, without the
<style type="text/css"> and </style> tags. Paste your CSS codes into a new document called style.css. Make sure it has the .css extension, or you will run into some problems.
Next, copy the following CSS and paste it at the top of your style.css file. Edit it as necessary. When you upload your theme to wordpress, wordpress uses the information listed below to get information about your layout.
/*
Theme Name: NAME OF YOUR LAYOUT
Theme URI: URL OF THEME’S WEBSITE (WEBSITE THAT THE THEME CAN BE ACCESSED FROM)
Description: DESCRIPTION OF YOUR THEME
Version: 1.0.0
Author: YOUR NAME
Author URL: YOUR WEBSITE URL
*/
Step 4: WordPress – Header
Go back to the generic layout you coded. Now copy everything from the top of the layout to the <div id="content"> tag. Get rid of the <style type="text/css"> and </style> tags, as well as the CSS codes inside them if you haven’t already.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>SITE NAME HERE</title>
</head><body><div id="container">
<div id="header">
<div id="nav">
Navigation Links</div>
</div>
<div id="content">
Save this as a new document called header.php. This makes up the header of your site. To make this wordpress-friendly, you need to add a few code snippets into the header of the code. The first code we use is going to call your css file. Insert this code under your <title> tags, but before you close the head tag.
<link rel="stylesheet" href="<?php bloginfo(‘stylesheet_url’); ?>" type="text/css" media="screen" />
If you use pingbacks, RSS or Atom feeds, you will need the following codes. If you’re not sure what they are, put them into your layout anyway. They are a way for other people to follow your site easily.
<link rel="alternate" type="application/rss+xml" title="<?php bloginfo(‘name’); ?> RSS Feed" href="<?php bloginfo(‘rss2_url’); ?>" />
<link rel="alternate" type="application/atom+xml" title="<?php bloginfo(‘name’); ?> Atom Feed" href="<?php bloginfo(‘atom_url’); ?>" />
<link rel="pingback" href="<?php bloginfo(‘pingback_url’); ?>" />
Making your page search engine friendly is very important if you hope people will find your site through searching on google, bing, or some other search engine. Find the <title> tags in your header.php file, and replace it with this code:
<title><?php if (is_home () ) {bloginfo(‘name’); }
elseif (is_category() ) { single_cat_title(); echo ‘ _ ‘;
bloginfo(‘name’); }
elseif (is_single() ) { single_post_title();}
elseif(is_page() ) { single_post_title();}
else { wp_title(”,true); } ?></title>
This code creates different title settings depending on wether your visitor has opened a single blog post page, or a search page, or somethihng else altogether. Save your header.php file.
If you want to make your site extremely wordpress friendly, copy the code below, and add in any extra header codes that you may have had in your layout (for example the sidebar).
<?php
/**
* The Header for our theme.
*
* Displays all of the <head> section and everything up till <div id="main">
*
* @package WordPress
* @subpackage RED by Enchant Me Not
*/
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( ‘charset’ ); ?>" />
<title><?php
/*
* Print the <title> tag based on what is being viewed.
*/
global $page, $paged;wp_title( ‘|’, true, ‘right’ );
// Add the blog name.
bloginfo( ‘name’ );// Add the blog description for the home/front page.
$site_description = get_bloginfo( ‘description’, ‘display’ );
if ( $site_description && ( is_home() || is_front_page() ) )
echo " | $site_description";// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
echo ‘ | ‘ . sprintf( __( ‘Page %s’, ‘twentyten’ ), max( $paged, $page ) );?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( ‘stylesheet_url’ ); ?>" />
<link rel="pingback" href="<?php bloginfo( ‘pingback_url’ ); ?>" />
<?php
/* We add some JavaScript to pages with the comment form
* to support sites with threaded comments (when in use).
*/
if ( is_singular() && get_option( ‘thread_comments’ ) )
wp_enqueue_script( ‘comment-reply’ );/* Always have wp_head() just before the closing </head>
* tag of your theme, or you will break many plugins, which
* generally use this hook to add elements to <head> such
* as styles, scripts, and meta tags.
*/
wp_head();
?>
</head>
Step 5: WordPress – Footer
Go back to the generic layout that you coded, and copy everything from the closing content div tag to the end of the page. Save it as a new file called footer.php. For my layout, my footer code simply contains the following.
</div>
<div id="footer">
<div id="footerText">
Layout by <a href="http://www.enchantmenot.info" target="_blank">Aashni at EnchantMeNot.info</a>.
</div>
</div></div>
</div></body>
</html>
Step 6: WordPress – Index (and other pages)
As said before, wordpress uses a form of php includes to load their pages. In order to get your page to work, you will need to use <?php get_header(); ?> and <?php get_footer(); ?> codes on every page in your theme. It literally "gets" the codes in the header and footer, and places them at thhe beginning and ending of the page. It’s important to remember to put the <?php get_header(); ?> at the very top of the page, and <?php get_footer(); ?> at the very end of the page. If you dont, then the codes you put before/after will mess up your layout. A sample page would look like this:
<?php get_header(); ?>The Content Goes Here
And you can put anything in this part of the code.
Pictures, codes, textareas, stories, blogs.. anything.
<?php get_footer(); ?>
The index (single and post) page in wordpress normally contains a loop that displays your blog posts. You can simply copy the loop code below. Unless you understand how to edit these codes, try not to.
<?php
function comment_plugger($show = 1, $limit = 0, $sep = ‘ ‘, $none = ‘ none’) {
global $wpdb, $tablecomments, $id;
$cid = ($show) ? ($id – 1) : $id;
$request = "SELECT DISTINCT comment_author_url, comment_author FROM
$tablecomments";
$request .= " WHERE comment_post_ID=’$cid’ AND comment_author <> ” AND
comment_author_url <> ”";
$request .= ‘ ORDER BY comment_author ASC’;
$request .= ($limit > 0) ? "LIMIT $limit" : ”;
$commenters = $wpdb->get_results($request);
if ($commenters) {
$output = ”;
foreach ($commenters as $commenter) {
if (!empty($commenter->comment_author_url)) {
$output[] = ‘<a href="’.$commenter->comment_author_url.’"
title="’.$commenter->comment_author.’">’.$commenter->comment_author.’</a>’;
}
}
}
if (is_array($output)) {
$sep = ", ";
echo implode($sep, $output);
} else {
echo $none;
}
}?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<h1><a href="<?php the_permalink() ?>" rel="bookmark" class="title" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h1><h5>Posted in <?php the_category(‘, ‘) ?>
<strong>|</strong>
<?php edit_post_link(‘Edit’,”,’<strong>|</strong>’); ?> on <span class=’st_facebook_buttons’ st_title=’{TITLE}’ st_url=’{URL}’ displayText=’share’></span><span class=’st_twitter_buttons’ st_title=’{TITLE}’ st_url=’{URL}’ displayText=’share’></span><span class=’st_email_buttons’ st_title=’{TITLE}’ st_url=’{URL}’ displayText=’share’></span><span class=’st_dbuzz_buttons’ st_title=’{TITLE}’ st_url=’{URL}’ displayText=’share’></span><span class=’st_digg_buttons’ st_title=’{TITLE}’ st_url=’{URL}’ displayText=’share’></span><span class=’st_sharethis_buttons’ st_title=’{TITLE}’ st_url=’{URL}’ displayText=’share’></span>
<?php the_time(‘l jS F, Y – g:ia’) ?> <!– by <?php the_author() ?> –> | <?php comments_popup_link(‘No Comments »’, ’1 Comment »’, ‘% Comments »’); ?></h5><div class="entry">
<?php the_content(‘Read the rest of this entry »’); ?>
</div><?php endwhile; ?>
<p class="alignleft"><?php next_posts_link(‘« Older Entries’) ?></p>
<p class="alignright"><?php previous_posts_link(‘Newer Entries »’) ?></p><p class="clear"></p>
<?php else : ?>
<h1>Not Found</h1>
<p>Sorry, but the page you requested cannot be found. If you feel this is an error, let me know.</p>
<?php get_search_form(); ?><?php endif; ?>
Step 7: Other Pages
There are other pages that you should code for your theme, such as the comments page, the sidebar if you are using one, the single.php and page.php. This has helped you create a very simple layout.
Step 8: Install and Use your Theme
Title says it all, upload, install and use your theme!























