Now is the part 2. If you haven’t read the part 1 yet, go here to read it. If in the part 1 we have make the graphics we need to build the template, now it is the time to play with CSS and HTML. But first, before we going further, we must first understand the WordPress template hirearchy. The WordPress template, in the very minimum, need at least two files, style.css and index.php. We can however have more files that recognized by WordPress to deliver different look on different requested page. But now, we create the standar template, at least we have header.php, footer.php, sidebar.php, index.php, comments.php, functions.php and style.css.
We first start with style.css. The first thing we did is write the details of the template, on the comment header of style.css. See here for more information.
Here is my style.css details.
Theme Name: Simple Golden Black
Theme URI: http://wordpress.org
Description: A simple template with elegant look.
Author: Jeffri Hong
Author URI: http://jeffri.me
Tags: two columns, fixed width, elegant, simple
This is pretty self explanatory, isn’t it? 🙂 This details will show in the themes selector on your WordPress admin page. Now let’s give some default properties.
h1, h2, h3, h4, h5, h6
Here we just give some properties on body and make sure that all div and header (h1, h2, …) have 0 margin and padding. We also give some properties for anchor (link) for normal one and hover one. That’s it.
Okay, let’s leave the style.css for a moment and move to header.php. Here is the header.php.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<title><?php bloginfo(‘name’); ?><?php wp_title(); ?></title>
<meta http-equiv=”Content-Type” content=”text/html; charset=<?php bloginfo(‘charset’); ?>” />
<meta name=”generator” content=”WordPress <?php bloginfo(‘version’); ?>” /> <!– leave this for stats please –>
<style type=”text/css” media=”screen”>
@import url( <?php bloginfo(‘stylesheet_url’); ?> );
<link rel=”alternate” type=”application/rss+xml” title=”RSS 2.0″ href=”<?php bloginfo(‘rss2_url’); ?>” />
<link rel=”alternate” type=”text/xml” title=”RSS .92″ href=”<?php bloginfo(‘rss_url’); ?>” />
<link rel=”alternate” type=”application/atom+xml” title=”Atom 0.3″ href=”<?php bloginfo(‘atom_url’); ?>” />
<link rel=”pingback” href=”<?php bloginfo(‘pingback_url’); ?>” />
<?php wp_get_archives(‘type=monthly&format=link’); ?>
<?php wp_head(); ?>
<h1><a href=”<?php bloginfo(‘url’); ?>”><?php bloginfo(‘name’); ?></a></h1>
<h4><?php bloginfo(‘description’); ?></h4>
<?php wp_list_pages(‘title_li=’); ?>
The head tag is actually copied from other WordPress template, we don’t need to care about it for now. The interesting part is in the body tag. You can see that I use div tag instead of classic table for layout. The header-content will contain the blog title and description while the header-menu contain the pages list. This won’t reproduce the output we want yet, it still need an assist from CSS. 🙂 Also, you can see that we call some WordPress function here. The bloginfo and wp_list_pages, see the links for more information. The body tag didn’t closed here, it will be closed on footer.php.
So now, let’s get going to the footer.php. It will contain this.
<h4>© Copyright <?php echo date(“Y”); ?> <?php bloginfo(‘name’); ?>. Powered by <a href=”http://wordpress.org/”>WordPress</a> and template by <a href=”http://jeffri.me”>Jeffri</a>.</h4>
<img src=”<?php bloginfo(‘template_directory’); ?>/images/foot-right.png” alt=”foot right bg” style=”float: left;” />
<?php wp_footer(); ?>
It is still nothing new here. Just another layout for footer with div. On the footer-content we will have copyright information. Notice there is img tag there. It is used as delimiter between the footer-content which have bright background and the footer dark background. This img tag is floating left as you can see.
Header and footer are ready now, next, we going to index.php.
OK, leave it like this first. You see we call get_header and get_footer function, this is the same as include the header.php and footer.php. We also have one div here. It will used later. Now, it is the time to play with the CSS and doing the positioning for header and footer.
We start from header.
background: #000 url(images/head-bg.png) repeat-x;
margin: 7px 2%;
#header-content h1 a
#header-content h1 a:hover
background: url(images/head-menu-side.png) no-repeat top left;
padding: 0 0 0 51px;
margin: 8px 2%;
padding: 0 25px 0 10px;
background: url(images/head-menu-bg.png) repeat-x;
#head-menu-list li a
Okay, a little explanation about this. If you see the header.php html, we have one parent div (header) with another two div (header-content and header-menu). The header-content will be placed on top left. But the header-menu will be placed on bottom right. We start with the parent div, we give black background with black background image (see the previous part to know what images we refer to here), and it is repeated horizontally. The width is 100% so this div will fill all of available width of your browser. The height is 150px, same as the background image height.
The header-content have margin of 7px on top and bottom, and 2% for left and right. Along with h1 (the blog title with line-height 70px) and h4 (the blog description with line-height 14px), so far we have filled 98px for the header-content. So the rest 52px (150 – 98) will be used for header-menu. This way, we calculate the remaining height to positioning header-menu to bottom. 🙂 It is probably not the best way, but it is also not a bad way, because our target now is Internet Explorer 6 or higher. I don’t want to care of another crappy old browser. 😛
Now we positioning the header-menu. We first float it to right, then choose the best margin for it. For the background, we use the delimiter image with no repeat, and to show the image, we add the left padding to 52px. We didn’t use different img tag for this as we do on footer, because we have the space for this image already. lol 🙂 Okay, the next is to positioning the list to horizontal. It is a bit tricky.
Before that, we give 0 padding and margin to the ul (head-menu-list) first. Then to the li, we give float left, this way, it will be listing horizontally. We also give some padding there (left and right only), and use the light background. For height, we make it same as line-height to make it center vertically. That’s it. Header done, it will now looks like below.
Now, the footer. Here we go.
background: #000 url(images/foot-base-bg.png) repeat-x;
padding: 0 20px;
Hmm…. The footer here is the parent div of footer-content, and we give it 100% width, same as header you see above. The height is 45px, same as the background image height. The background is the dark one, while the footer-content will have bright background. We also give clear: both to make sure it clear all floating element.
The footer-content is floating left, same as the image delimiter you see on the HTML. The height is also 45px, width on 70% also some margin and padding to make sure it shows fine. 🙂 For the h4, I only change the font size and line height to make sure it centered vertically. Now it should looks like this.
Not bad. That is enough today. Next day, we will start creating the sidebar and the content. 🙂 See ya!