WordPress Theme – My header.php

March 24th, 2009 | Author: Sunny

This is code for my header.php:


<?php
  /**
  * @package WordPress
  * @subpackage mySmallProgramTheme
  */
  ?>
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<head profile="http://gmpg.org/xfn/11">
  <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

<title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
  <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'); ?>" />
  <link rel="shortcut icon" href="<?php get_bloginfo('url') ?>/wp-content/themes/mysmallprogramtheme/image/favicon.png" type="image/png" />

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  <?php if (is_singular() ) wp_enqueue_script('comment-reply');
  ?>
  </head>
  <body>
  <div id="page">
  <div id="header">

  <div id="headerimage">
  <a href="<?php echo get_option('home'); ?>" ><h1><?php bloginfo('name'); ?></h1></a>
  <div class="description"><?php bloginfo('description'); ?></div>
  </div>

First, I have setup some header information with bloginfo() in the Header tag. You may just take a look how I did that because you mostly will put the same header as mine.

After the Header Tag, I defined a Wrapper layer “page”


<div id="page">

This is the wrapper for all contents in my blog. In this wrapper, usually you will define four different parts(or layers).

1. Header
2. Content
3. Footer
4. Sidebar

And for this example, this file is called header.php, so I will define our “Header” layer here. Next 5 lines, I have defined my “Header”:


 <div id="header">

  <div id="headerimage">
  <a href="<?php echo get_option('home'); ?>" ><h1><?php bloginfo('name'); ?></h1></a>
  <div class="description"><?php bloginfo('description'); ?></div>
  </div>

In the header layer, I have defined another wrapper called “headerimage”. This is because I want to wrap my Blog title and description in my header layer.

Later on, I will show you how I created index.php for my content layer. footer.php for my footer layer, and sidebar.php for my sidebar layer.

One more thing I forgot to mention, in header section, there is a php code:


 <?php if (is_singular() ) wp_enqueue_script('comment-reply');
  ?>

is_singular() will check if this page is a single post (only one post on the page, and actually there is a template file called single.php that you may also define it yourself or by WordPress default template. single.php is liked index.php which I will call my header, sidebar, and footer files here except it only displays one post per page). In my case, I only want to include javascript for replying a comment when someone land on single.php, or else the code should not be included.

So, it looks pretty simple right? However, don’t forget the code above has no decoration, so you will have to define your own CSS style for each layer and wrapper, or otherwise you will only see plain text on your header.


body {
	font-size: 62.5%; /* Resets 1em to 10px */
	font-family: Arial, Helvetica, sans-serif;
	background: #ffffff;
	color: #333;
	text-align: center;

}

#page {
	border: none;
	background:url(image/layoutbg.png) repeat-y bottom center;

}

#header {
	background: url(image/headerpic.jpg) no-repeat top center;
}

#headerimage {
	width: 830px;
	height: 195px;
}

#header h1 {
	font-size:36px;
	text-align: center;
	color: #903;
}

#header a, #header a:visited {
	text-decoration: none;
	color: #903;
}

#header a:hover {
	text-decoration:underline;
}

#headerimage .description {
	font-size:14px;
	text-align: center;
	color: #666;
	font-family:Georgia, "Times New Roman", Times, serif;
	font-style:italic;
}

body {
	margin: 0px 0 20px 0;
	padding: 0;
}

#page {
	margin: 0px auto;
	padding: 0;
	width: 830px;
}

#header {
	margin: 0 0 0 0px;
	padding:0;
	height:195px;
	width: 830px;
}

#headerimage {
	margin: 0;
}

#header h1 {
	margin: 0;
	padding:70px 0px 0px 0;
}

#headerimage .description {
	margin: 0;
	padding:1px 15px 0 0;
}


Please forgive my mess. :) I defined them twice because I kinda modified from the default WordPress Theme which it separates the style of structure and coloring in two parts. You may just group them in one depends on what you like.


10 Responses to “WordPress Theme – My header.php”

  1. UFC betting says:

    Interesting site, nice design, i have bookmarked it for the future referrence

  2. Imissorgo says:

    Great site this blog.sunnycyk.hk and I am really pleased to see you have what I am actually looking for here and this this post is exactly what I am interested in. I shall be pleased to become a regular visitor :)

  3. Sunny says:

    thanks. Hope my stuff can help :)

  4. Gulsegloletut says:

    I’m new to this blog. Apologize for asking this though, but to OP…
    Do you know if this can be true;
    http://www.bluestickers.info/ringtones.php ?
    it came off http://ringtonecarrier.com
    Thanks :)

  5. CHEAP VIAGRA says:

    ????????????? ????? ?? ??????????? ???????? ??? ?????? I want to say – thank you for this!

  6. Arianaburb says:

    I really liked this post. Can I copy it to my site? Thank you in advance.

  7. The article is ver good. Write please more

  8. Sunny says:

    Katty: I will try my best to continue this writing.

Leave a Reply

You must be logged in to post a comment.