Home » Posts » Adding Asides in Wordpress

Let’s preface this article by first discussing what an aside is and does in wordpress:

An Aside, in blogs, passes small bits of information to your readers without requiring a full post. This can come in handy for many reasons, and you’d be suprised how often you might find yourself needing to inform your readers of something without requiring a well thought-out article/post.

Asides defined by Plugins
The easiest, and probably most often used way of adding asides to your site, is by way of plugins. These plugins are designed so that it minimizes/eliminates actual need for hard-coding. The most commonly used are MiniPosts2, SideBlog, and AsideShop. This may be a easy/fast solution for a new*er user, but for me, I need more control and besides: I like to get my hands dirty.

The Dirty
If you are comfortable editing PHP files, then this approach is for you.

I. Make a backup of your theme’s index.php, this might come in handy if you manage to mangle your index.php file beyond repair. Did I mention that is the file we will be editing? Ok, good.

II. In your Administration Panels > Manage > Categories add a category for your Asides. You can call it Asides if you want. Note the Category ID number of the category. In the following examples we will use category ID 14, but you change this to the category ID of your Asides category.

III. Open your Theme’s index.php template file in a text editor, and search for

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

Comment it out like this:
< ?php //if (have_posts()) : while (have_posts()) : the_post(); ?>

IV. Under this code, paste the following:

< ?php
if ($posts)
{
function stupid_hack($str)
{
return preg_replace('|\s*(ul class="linklog")|', '', $str);(/ul)
}
ob_start('stupid_hack');
foreach($posts as $post)
{
the_post();
?>

V. The next line should be your date call < ?php the_date(); ?> Under that, paste this:

< ?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”)# < ?php edit_post_link('(e)'); ?>(/span)(/li)

< ?php else: // If it's a regular post or a permalink page ?>

VI. At the bottom of the index.php file, find:

< ?php endwhile; else: ?>

< ?php _e('Sorry, no posts matched your criteria.'); ?>

< ?php endif; ?>

VII. Delete those lines. And instead, paste these lines:

< ?php endif; // end if in category ?>
< ?php
}
}
else
{
echo '

Sorry no posts found.’;
}
?>

That’s it. Asides should now be working. Only thing that remains is styling the CSS.

Styling Your Asides

What we’ve done is create a very basic style. You should add your own style to blend it in with the rest of your site. To style the Asides, add these example lines to the CSS:

ul.linklog li {
border:1px solid #ff0000;
font:Verdana;
font-size:14pt;
background-color:#ffff00;
}

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

What next?

Leave a comment

If you like, you can format your comment using these HTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>