This Post
  • HOME PAGE
  • ABOUT
  • ARCHIVES
  • SITEMAP
 
« EntreCard - Pick Of The Week - 11/01/08 Deep Linking Comments »
 
13
Jan

How To Modify A WordPress Theme - Part 3

by admin

WordPress Series
This is the next part of the WordPress series. In the last part, Modifying a WordPress Theme - Part 2, you styled the sidebar. In this part you shall style the post itself. To do this part you need to have completed the last part or at least download the modified files.

When you write a post and publish it, you are actually making a number of copies at the same time. They can be found in Archives, Categories, Searches, the front page, one for each Tag you used and of course the single page. Some people even put their post in two or more categories and this doubles the amount of duplicates that you already have!

This is bad for SEO as it is duplicate content as far as the search engine is concerned. This is one reason why, if you look at this blog, the only place you can see a full post is on the singles page. It is also why each post is in only one Category.

Some blogs show the full post on the front page as well. This has it’s pros and cons. Some people will not click a link to read the full article so you may lose them. If you have too much content on the front page some will not wait for it all to download and you will lose them. If you look at most of the probloggers they are moving over to excerpts on the front page.

Page Layout

Single Page LayoutIn this part, I will show you how to style the single page. First of all, in HTML-kit, load up single.php. If you look at the diagram to the right, I have gone through the single.php and drawn the major elements of the page so that you can better visualize what the code means. You may notice that the code is indented this is another visual hint.

Open up your browser and go to a single post page. At the top of the page you will see the navigation, which is repeated further down just above "Post a Comment". Next is the post’s Title, this is usually a h2 tag (h = header 2=2nd largest header).

<mini-rant> In a lot of themes I have seen, this is a link, WHY?!? You are already on the page, clicking on it just causes more network traffic.</mini-rant>

Then you have the body of the post (entry-content) followed by the meta data (entry-meta) this includes the date, author of the post etc. The last bit is the comments area. All of this is held inside the content div.

You may have noticed that everything is touching the left side of the browser window, this does not look very good, it needs a bit of space to breath. As everything is inside the content div, you can apply some padding to only the left side of it.

Open style.css and go to line 28 and press enter then add:

div#content {
  padding-left:10px;
}


Save it and then refresh the browser, looks better, yes?

The Post Title

Now we turn our attention to the Title area. At the moment there is only the title. You can have whatever you want in that area. If you look at the Title area for this post you will see I have the date and author there, some blogs put all the meta info there. Have a look around other blogs, see what you like, then decide what you want to be there. I shall show you how I did mine and then how to vary it.

Title HeaderSo that you can put things in place, you will need an arrangement of divs as shown here. As you can see there are two divs inside another div, in code this would be:

<div>
   <div>
   </div>
   <div>
   </div>
</div>

Now give them names so that we can style them, in this case we shall use classes:

<div class="posthdr">
   <div class="datebox">
   </div>
   <div class="hhdr">
   </div>
</div>

Before we go any further you should start putting this into single.php. Open it in HTML-kit and go to the end of line 12 and hit enter, then type in the above code.

Now we shall put some text into the divs. Inside the datebox div type:

<p><small><?php the_time('j') ?></small><br />
<?php the_time('M') ?></p>

I have put the date inside a paragraph (<p>). the_time() is a php function that will return the date in different formats. In this case the first has a j to show the day part of the date and the second one has an M to show the first three letters of the month. We want them on seperate lines so there is a break (<br />) at the end of line 15.

Then inside the hhdr div type:

<h2 class="entry-title"><?php the_title(); ?></h2>
<p>By: <?php the_author() ?></p>

The first line is the post title, if you look below all the code you entered you will see the same line, you can safely delete it. The second line is a paragraph that holds the name of the author that is shown by using another php function the_author(). Once you’ve typed it all in save single.php.

Now we shall style it. Load up style.css and go to the end of line 39 and hit enter. Then enter the following:

div.posthdr {
  margin-bottom: 15px;
  border: 1px solid black;
}
div.datebox {
  float: left;
  width: 50px;
  background: #90befc;
}
div.datebox p {
  text-align: center;
  font-size: 1.2em;
  font-weight: bold;
  margin: 5px;
  padding: 0px;
}
div.hhdr {
  float: left;
}
div.hhdr h2 {
  font-size: 2em;
  margin: 0px 0px 0px 10px;
}
div.hhdr p {
  font-size: .7em;
  margin: 0px 0px 0px 10px;
}


Then save it. I have given the posthdr div a black border so that you can see it. When I am developing css I do this to all the divs (different colors) so that I can see where they are. I also gave the datebox div a light blue background for the same reason.

If you have two divs together they will be on top of each other, to get them side by side you have to float them. A float is like an align it can go left or right, in this case both the datebox and hhdr are floated left.

The posthdr div already has all margins set to zero, I wanted a small gap between it’s bottom and the post’s text so I have set margin-bottom to 15 pixels.

The text inside hhdr would naturally be tight up against the datebox so I have given both the h2 and the paragraph a left margin of 10 pixels.

Title PreviewThe rest of the css is just for sizing the text. Now view the page in the browser, it should look something like the image to the right. If not, go over the code and make sure you didn’t miss anything out.

We just have two things left to do, first you can delete the line:

border: 1px solid black;

From the posthdr div. The other thing is the datebox. I want a gradient background box. To do this I took a screen capture of the page and then in PhotoShop I made a box the same size as the light blue box and saved it as datebox.jpg. You can right-click and save image. This is saved in the image folder at:

FLASHSTICK:\www\wordpress\wp-content\themes\sandbox\images

You can then change the div.datebox background css to:

background: url(images/datebox.jpg) no-repeat;

Save it and then preview in the browser.

There is one drawback to using this layout. If your post’s title is too long it will go over the single line and will not display so nicely. Therefore it should be used only with fixed width layouts. Also when you create your post title you should really be writing short snappy titles that attract the readers attention.

The Post’s Footer

Once the visitor has read the article, what do you want them to do? Sign up to your rss feed, continue reading other articles, vote for you on a social site, buy something, add a comment. These are all valid objectives, the footer should give the reader a choice of one or two of these options.

There is also other information about the post that can be included in the footer, for example the tags that you are using for the post and the post’s trackback URL.

If you look at the current footer it is a mini paragraph in it’s own right, with a lot of info in it. This can cause the reader to skip it, so let’s clean it up.

Highlight lines 31-52 and delete them, this should leave:

<div class="entry-meta">
 
</div>

If you are going to use tags (I recommend that you do), then add this line between the tags:

<?php the_tags('<strong>Tags</strong>: ', ', ', '<br />'); ?>

This uses a php function, the_tags(), to print a list of all the tags that are used for this post followed by a break (<br />). If there are no tags the line will not be printed. Below this line add:

<strong>Category</strong> <?php the_category(', ') ?> |
<?php edit_post_link('Edit', '', ' | '); ?>

On this line we use the php function the_category() to print the Category the post is in, followed by the edit button. If you wish you could give the entry-meta div a colored background. You do this by adding this to the end of the style.css:

.entry-meta {
  background: #90befc;
  padding: 5px;
}


If you don’t like this you could instead change the color of the links like this:

.entry-meta a {
  color: #5050fc;
}
.entry-meta a:hover {
  text-decoration: underline;
}
.entry-meta a:visited {
  color: #666;
}


This will make the links a blue color. When you move the mouse over a link it will become underlined. If you have clicked on one of the links and then returned to the page the link will be a gray color.

Save and preview in the browser and you’re finished. Here are the updated style.css and single.php, you will need to change their extensions from txt to css and php respectively and remove the -3 from the filenames.

Next time we shall continue to modify a WordPress theme by styling the comments section.

Related posts:
  1. How To Modify A WordPress Theme - Part 4
  2. How To Create A Wordpress Theme - Part 4
  3. How To Create A WordPress Theme - Part 2
  4. How To Create A Wordpress Theme - Part 5
  5. How To Create A WordPress Theme - Part 9
Subscribe to RSS feed
stumble me

Tags: comments, navigation, page layout, post, theme, title, wordpress, wordpress theme
Category wordpress | Print This Post Print This Post |

There are 15 Comments

  1. How To Modify A WordPress Theme - Part 3…

    This is the latest in my WordPress Series dealing with how to modify a WordPress theme. In previous parts you changed the header, navigation bar and sidebar. In this part I show you how to use Cascading Style Sheets to modify the appearance of a post o…

    Scribbled by bloggingzoom.com on 13/01/08 at 10:38 pm
  2. hi,
    i need your help,my wordpress blog is in bad shape.
    can please take a look. it’s side bar is missing and appeared at the bottom

    my site damia.lankapo.com

    really appreaciate ur help
    thanks

    Scribbled by Azlan on 14/01/08 at 2:34 pm
  3. @Azlan: I’ve checked your page, please see my email.

    Scribbled by Colin King on 14/01/08 at 8:03 pm
  4. I wanted to check out the previous posts in the series, but the link at the top goes to this post not post#2.
    Thought I might want to start at the beginning of the series. If the other two are anything like this one, I am sure there will be some really useful info.

    Scribbled by Evangel on 14/01/08 at 11:17 pm
  5. Hi, what do you charge to check and fix duplicate content problems on a blog? I know mine must be a mess. I post many of my posts to more than one category and when I started to blog I didn’t use “more” or custom excerpts for the posts.

    By the way, I love your blog’s design - nice clean look and easy to read, colors great too!

    Scribbled by Joni Solis on 14/01/08 at 11:24 pm
  6. @Evangel: OOps. My bad, I forgot to put the address in there fixed now. Thanks. :)

    @Joni: thx, I created it myself :) Have replied via email.

    Scribbled by Colin King on 15/01/08 at 1:28 am
  7. Just finished reading the series. Great tips and explanations!

    I need to go through the destroy my new themes I started using. I’ve done some very basic stuff already but I really need to go through and do some fine tuning. These articles will help.

    Scribbled by Chris Schaffer on 15/01/08 at 5:09 pm
  8. @Chris: After this part of the series is finished, I will be going through how to create a theme from scratch. I shall be looking at both regular and magazine type layouts.

    Scribbled by Colin King on 15/01/08 at 10:44 pm
  9. An excellent series of easy to understand tutorials, Colin. I will read your create a theme one with interest. I use the sandbox theme too but have not made too many changes as yet. I can’t decide on the design!

    Scribbled by Sue on 16/01/08 at 11:39 pm
  10. @Sue: thx :) I’m just using the Sandbox theme for the tutorial as it was there and built for modders. A good way of deciding on a unique theme is to write the main topic of blog followed by 3-4 phrases that express what you want a visitor to think or how you want them to react. Then mind-map from each of these, go wild whatever comes to mind. from there you can look up color equivalences, decide if the majority of phrases are masculine/feminine (boxed, straight lines / curves, open areas. etc. I shall go into this deeper in the first post, but that should get you going.

    Scribbled by Colin King on 17/01/08 at 12:29 am
  11. I was just discussing a few minutes ago the fact that our theme does no display the author’s name (and with 5 of us writing it can get confusing…), but using your tips our posts now say who they are by! With an exclamation mark after the name! Yeah!

    Scribbled by Erica on 18/01/08 at 12:43 am
  12. @Erica: Synchronicity at work ;)

    Scribbled by Colin King on 18/01/08 at 4:20 pm
  13. […] going on you should have read the last post, How To Modify A WordPress Theme - Part 3, and you should have completed the tasks in […]

    Scribbled by How To Modify A WordPress Theme - Part 4 | CK Marketing on 19/01/08 at 7:33 pm
  14. Hi, I am trying to read your series and learn how to incorporate it into creating a WordPress Template for my Website’s “Blog” section. I have yet to install WordPress on my shared host server (Godaddy.com Linux Hosting). Here is the link for the blog webpage: http://blog.myt4w.com. My website uses DreamWeaver CS3 plugins from ProjectSeven.com, specifically the Pop Menu Magic for the navigational bar. How can I use your tutorial to help me customize a WordPress theme for my website? I have read several of your tutorials but they do not seem to relate to a website that already has a template designed. Also very early on you said do NOT use a visual editor. DWCS3 is a visual editor. If your tutorials can not help can you direct me to where I can find another one that maybe can direct me better. Thanks!

    Scribbled by Dante on 05/04/08 at 1:49 pm
  15. @Dante: I have deleted your other comment as it is essentially the same as this one. I seriously doubt that POP Menu Magic is compatible with Wordpress however I have seen some drop-down menu plugins or you could create them yourself, there are lots of tutorials. I have DW CS2 and it still had some formatting problems, but you can, and really should, learn coding and use the code window to minimize any changes. DWCS3 still has the choice of visual, visual and code or just code.

    To add WP to an existing non-blog site all you need to do is create a directory and install the blog inside it.

    I would suggest, if you haven’t already, that you setup a local server so that you can work on the design before uploading. I show you how to do that in WordPress setup, Themes and Plugins.

    If you are okay with coding then checkout How to get started creating webpages which leads on to the create a theme series.

    If you need any other help gve me a shout here.

    Scribbled by Colin King on 05/04/08 at 6:36 pm

What are your thoughts?

What do you think? Leave a comment. Alternatively, write a post on your own blog, this blog accepts trackbacks [trackback].

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Please read the Comment Policy before commenting.

  • Check out one of my favourite sites

    Changes Daily. This is not an Ad!



  • Categories

    • Affiliate Marketing
    • Blogging
    • General
    • Guest Posts
    • List Building
    • Monthly Reports
    • Product Reviews
    • Social Networking
    • Traffic
    • Wednesday Links
    • wordpress
  • Recent Posts

    • A New PC05.11
    • Get More Traffic From Your Tutorials05.8
    • A Surprise In The Mail04.30
    • How To style your Comments - Part 304.28
    • How to Style Your Comments - Part 204.26
    • How To Style Your Comments - Part 104.23
    • The March $100 winner, a problem and a rant04.21
    • Valid XHTML For The EntreCard Widget04.15
  • Bookmarks

    Add to Technorati Favorites
  • Top Commentators

    • Chelsa (1)
    • anto (1)
 

This site's design and contents are ©2007-2008 by CK Marketing - All rights reserved Worldwide

This blog is protected by Dave's Spam Karma 2: 3231 Spams eaten and counting...