Dissection of a WordPress theme: Part 2

Apr 22, 2005 | Tags: , , , , , , | Written by Administrator

Step 2 - Shrinking the page

Currently we have a full-screen theme, with the content and sidebar fluid. That is, they expand and contract to make use of available space. This is nice but has a few problems:

  • Short paragraphs turn into single lines when the browser is maximised
  • Layout is not fixed and we can’t guarantee the position of anything
  • Hard to read at full width, impossible to read at minimum width
  • Internet Explorer goes nuts at small widths

A lot of research has been done on the optimum line length, and it has shown that people read best when the length is fairly small. Open any book or magazine and you will see that large amounts of text are always broken into small columns, allowing the eye to break down the text without getting lost.

Part one introduced a page margin of 20 pixels in an effort to introduce space into the design. Let’s take this one step further. The main purpose of a blog is to be read, and we don’t want people to be dissuaded from the content by a crowded presentation.

First we reset all margins and padding. Browsers can be inconsistent, and this tries to make them think the same. To do this we introduce a global style at the start of style.css:

*
{
  padding: 0;
  margin: 0;
}

The asterisk represents everything, so acting as a global style. If we include this as the first style then the normal cascading rules allow it to be overridden in further styles.

It’s time to look at the theme in action.

Option

The removal of all margins and padding has squashed everything together. Not to worry, as this will get changed later.

Resetting the body style

Now let’s remove some of the styles we introduced in the previous guide. Doing this will increase flexibility and we can then re-introduce them into more appropriate elements. Empty the body style in style.css:

body
{
}

Wrapping up the content

The first step in shrinking the page is to introduce a wrapper to contain the sidebar and contents. This is done so we can style both elements without interfering with the header and footer. Hopefully this will make sense once you see the effects.

Edit index.php and add the highlighted wrapping elements (line 3 and 51):

  1. <?php get_header(); ?>
  2. <div id="wrapper">
  3.  
  4.   <div id="content" class="narrowcolumn">
  5.  
  6.   <?php if (have_posts()) : ?>
  7.    
  8.     <?php while (have_posts()) : the_post(); ?>
  9.  
  10.        
  11.       <div class="post">
  12.         <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
  13.  
  14.         <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
  15.  
  16.        
  17.         <div class="entry">
  18.           <?php the_content('Read the rest of this entry &raquo;'); ?>
  19.  
  20.         </div>
  21.    
  22.         <p class="postmetadata">Posted in <?php the_category(', ') ?> <strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?>  <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></p>
  23.  
  24.        
  25.         <!--
  26.         <?php trackback_rdf(); ?>
  27.  
  28.         -->
  29.       </div>
  30.  
  31.     <?php endwhile; ?>
  32.  
  33.     <div class="navigation">
  34.       <div class="alignleft"><?php posts_nav_link('','','&laquo; Previous Entries') ?></div>
  35.  
  36.       <div class="alignright"><?php posts_nav_link('','Next Entries &raquo;','') ?></div>
  37.  
  38.     </div>
  39.    
  40.   <?php else : ?>
  41.  
  42.     <h2 class="center">Not Found</h2>
  43.  
  44.     <p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
  45.     <?php include (TEMPLATEPATH . "/searchform.php"); ?>
  46.  
  47.   <?php endif; ?>
  48.  
  49.   </div>
  50. <?php get_sidebar(); ?>
  51. </div>
  52.  
  53. <?php get_footer(); ?>

Help me to save time by reading these instructions!

If you are asking a question please read the FAQ to see if it has already been answered. All support questions should be directed to the support forum. Thanks!

Share This

Comments

Comments are shown on the first page.

Home | Software | Terms & Conditions | Sitemap | John Godley © 2008
Close
E-mail It