How To: Set up and Style Asides in WordPress

As your blog grows more than likely you have settled into a small list of primary focuses. But what if you want to stray from those without detracting from the primary posts?

Enter: Asides.

Asides are quickly becoming popular. They are easy to setup and make a nice addition to your focused blog.

Here is a step-by-step walk through of how I set up asides.

Note: This is for people who are comfortable editing PHP and CSS. I simply followed a tutorial from the WordPress Codex and then tweaked my CSS to get my asides to look how I wanted. Also note that this tutorial is for putting asides within the main content area of your blog and not your sidebar. If you’re using the Cutline theme, then skip my tutorial and go read Ben’s.

1: Make an Asides Category

  1. From your WordPress Admin Panel click on Manage –> Categories –> Add New
  2. Title the category whatever you want, (it doesn’t have to be ‘asides’) and add it.
  3. In the list of categories, note the ‘Category ID’ of your asides category.

2. Backup your theme’s index.php

This way if you goof something up, you can just erase over your mistakes and get things back to the way they were.

  1. In the folder of your site’s current theme backup the index.php file.
  2. To back up this file you can either download it to your desktop, or just go into the WordPress theme editor, and copy all the text from the index.php file and then paste it into a text editor.
  3. If you download it, it is located in http://yoursite.com/wp_content/themes/YOUR CURRENT THEME/index.php

3. Edit your theme’s index.php

  1. In a text editor or in your WordPress theme editor open up the index.php file
  2. Find:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    Now comment it out like this:

    <?php //if (have_posts()) : while (have_posts()) : the_post(); ?>
    
  3. Under that line, paste this:
  4. 
    <?php
    if ($posts) 
    { 
    function stupid_hack($str) 
    { 
    return preg_replace(’|</ul>\s*<ul class=”linklog”>|’, ”, $str); }
    ob_start(’stupid_hack’);
    foreach($posts as $post)
    { 
    start_wp(); ?></ul>
    
  5. The next line will be your date call, if you have one - I don’t.

    (<?php the_date(); ?>)

    If you have a date call then post this text beneath it if you want the asides to be posted after the date. If not then add this text after what you just added.

    Note: Here is where you need to recall the id number of your aside category. Put that in place of 14 from this example.

  6. <?php if ( in_category(14) && !is_single() ) : ?>
    <ul class=”linklog”>
    <li id=”p<?php the_ID(); ?>”>
    < ?php echo wptexturize($post->post_content); ?>
    <span><?php comments_popup_link(’(0)’, ‘(1)’,
    ‘(%)’)?> <a href=”<?php the_permalink(); ?>”
    title=”Permalink: <?php echo 
    wptexturize(strip_tags(stripslashes($post->post_title), ”)); ?>”
    rel=”bookmark”>#</a> <?php edit_post_link(’(e)’); ?></span></li>
    </ul>
    <?php else: // If it’s a regular post or a permalink page ?>
    
  7. I edited the above code to look like this. I didn’t like having a comments link and a permalink. Also I wanted it to say “X comments” not just “X”. My code looks like this:
  8. <?php if ( in_category(14) && !is_single() ) : ?>
    <ul class=”linklog”>
    <li id=”p<?php the_ID(); ?>”>
    <?php echo wptexturize($post->post_content); ?>
    <span>< ?php comments_popup_link(’{0 comments}’, ‘{1 comment}’,
    ‘{% comments}’)?>
    <?php edit_post_link(’(e)’); ?></span></li>
    </ul>
    <?php else: // If it’s a regular post or a permalink page ?>
    
  9. At the bottom of your index.php file find this:
  10. <?php endwhile; else: ?>
    <p><?php _e(’Sorry, no posts matched your criteria.’); ?></p>
    <?php endif; ?>
  11. Delete that and replace it with:
  12. 
    <?php endif; // end if in category ?>
    <?php
    }
    }
    else
    {
    echo ‘<p>Sorry no posts found.’;
    }
    ?>
    
  13. Save your new index.php file

4. Styling your CSS

Below is the CSS I am using for my asides.


ul.linklog { 
    padding-left:15px;
    font-family:Georgia, Times New Roman, Times, serif;
    font-size: 11px; 
    background: url(images/navbulle.gif) top left no-repeat; 
    border-top: none;
    margin: 0px 20px 35px 5px;  
    list-style-type: none; 
}

ul.linklog a { text-decoration:none; }

Here’s what it means:

ul.linklog
I took out the li tag so it doesn’t read ul. linklog li
What this does it keep my asides from being indented as much as a bulletpoint. I wanted them left aligned with the rest of the content.

background: url(images/navbulle.gif) top left no-repeat:
This is the star that I’m using as my ‘bullet point’. It’s a 10×10 pixel gif image. If you don’t want to make your own bulletpoint then edit the “list-style” attribute.

padding-left:15px;
This moves my text over enough to get out of the way of the star.

margin: 0px 20px 35px 5px;
This is short hand for the margins around the text. It goes in clockwise order starting with the top margin: Top, Right, Bottom, Left.

list-style: none;
This keeps my asides from having a bullet-point.

5. Start Asiding

That should do it. Now when you go to post an aside, just assign it to your aside category.

I’m sure you’ll have to play around with things to get it the way you want with your theme. And if it makes you feel better it took me longer to write this tutorial than it did to install my asides…

11 Comments »

  1. Ian Barker said:

    This looks like a good idea. Thanks for posting this because it inspires me. I think I will find this useful on my blog.

    Posted on January 7, 2007 at 6:21 pm

  2. The other Andy said:

    Sweet idea.

    Posted on January 7, 2007 at 7:05 pm

  3. Shawn said:

    Note: There was a few elements missing that I just fixed.

    In steps 3 & 4 under edit your theme’s index.php I forgot to mention that you have to substitute then #14 for your aside’s categorie id number.

    Posted on January 7, 2007 at 8:03 pm

  4. Randy Bohlender said:

    As more of a ’stream of conscousness’ blogger, I’d do better to accentuate the three or four posts a month that actually stick to my theme. If I had one.

    My favorite aside? Aside of fries.

    Posted on January 7, 2007 at 9:06 pm

  5. Shawn said:

    @Randy: Long time no see my friend. I know a lot of people that absolutely love your blog. No focus. Random thoughts. Always easy to read and interesting.

    So are you offering me Wendy’s?

    Posted on January 7, 2007 at 9:39 pm

  6. Ian Barker said:

    I got it running on my blog. Except I used a plug-in called Sideblog. Very easy.

    http://katesgasis.com/2006/05/02/sideblog-plugin-v30/

    Thanks for the inspiration Shawn.

    Posted on January 8, 2007 at 2:02 pm

  7. Shawn said:

    @ Ian: Thanks for the link. Do you know if it works if you don’t want asides in your sidebar?

    Posted on January 8, 2007 at 9:52 pm

  8. Ian Barker said:

    I think it would, although I don’t know. You just have to insert some PHP code in your sidebar, so I see no reason why you couldn’t just insert it directly into your main post area.

    Posted on January 8, 2007 at 10:12 pm

  9. steve offutt said:

    S: you are always on the up and up!

    Posted on January 16, 2007 at 2:21 am

  10. Rock Your Blog: Resources » Fighting to Stay Awake said:

    […] Set up and style Asides in WordPress - via Yours Truly […]

    Posted on January 19, 2007 at 4:52 pm

  11. Are You New to Blogging? | Fighting to Stay Awake said:

    […] How To Setup and Style Asides […]

    Posted on March 7, 2007 at 3:13 pm

Dem's fightin' words...