Wordpress Tip: The Easy Way to Show a Popular Post List

Some may recognize the above screenshot as the 'Must Reads' section from the blog of one of the best Wordpress theme designers: Chris Pearson. In one of his most recent posts he explained how he uses categories. In this in-depth article, he mentions that categories are what powers the 'Must Reads' and 'Worth a Look' lists on the side of his site.
In my short tutorial here, I am going to show you how to easily do it for yourself.
First, we create another Loop and specify with the query_posts function that we only want to show a particular category. In this case, I have created a specialized category called 'Popular' and only use it for the purpose of this list.
<h3>Popular Articles</h3>
<ul>
<?php query_posts('category_name=popular'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
<?php the_excerpt(); ?></li>
<?php endwhile; ?><?php endif; ?>
</ul>
After we add that code to any theme template file (I've added it to sidebar.php) all that is left is to add posts to the category 'Popular'. From now on, just as long as a post is in that category, it will show in this list. All you need to do is add and remove posts from this category to alter what this list displays.
Also, in the code above, I just show the title and except, but you are free to customize it any way you see fit. Just about anything that can be used within the regular Loop is fair game. Here is a list of tags that should work for you.
Told you it was easy.

April 15th, 2008
5:01 am
[...] explains how to create a category loop to display those posts in your sidebar. Chris Pearson has also written a great post about the ideal [...]