Posted on 1 October, 2008 By 125 Comments

WordPress – How to List Recent Posts from One Category


There was an error in the code example that has been corrected. The code will now work in a sidebar text widget.

Categories (by Drift Words)

At the bottom of the sidebar on my other pages like About, I have a list of my recent WordPress posts. Go ahead, go take a look and then come back – I’ll wait.

This is easily done by adding a loop to the sidebar and a query that locates posts from just one category.

Please note that this will only work with standard sidebars. If you are using widget ready sidebars you will want to install the Exec-PHP plugin and then add the code to one of the text widgets. Exec-PHP allows you to run PHP code in posts, pages and widgetized sidebars.

<?php query_posts('category_name=wordpress&showposts=5'); ?>
<?php while (have_posts()) : the_post(); ?>
        <li><a href="<?php the_permalink(); ?>">
          <?php the_title(); ?>  
          </a>  </li>
        <?php endwhile; ?>

The main part of this is the standard WordPress loop that you will find on most of your template files.

<?php while (have_posts()) : the_post(); ?>
        <li><a href="<?php the_permalink(); ?>">
          <?php the_title(); ?>  
          </a>  </li>
        <?php endwhile; ?>

What differs is the query_posts code right before the loop.

<?php query_posts('category_name=wordpress&showposts=5'); ?>

The query_posts code is telling WordPress to locate my last 5 posts in the WordPress category. The loop then runs the code to display them.

This is a great way to highlight the posts in your strongest or most popular category rather than just using a list of all the recent posts.

photo credit: drift-words

web hosting by media temple

Keep Reading:
Posted In : WordPress Tips

Did you enjoy this article? I can assist you with your WordPress or Facebook project. Contact me and I will provide you with an estimate. You can also connect with me on Facebook or follow me on Twitter. If you are looking for Hosting, WordPress Theme, Newsletter or other recommendations, please view my detailed list.

125 Responses to “WordPress – How to List Recent Posts from One Category”

  1. 10 WordPress ‘HOW-TO’ to Give it the Quality it Deserves
  2. (Anti) Social-Lists 9/13/09 | (Anti) Social Development
  3. FAQPAL Blog
  4. 23 articles and resources to improve your Wordpress life! |
  5. WordPress: List Posts For A Category | The OS Quest
  6. 10 WordPress ‘HOW-TO’ to Give Your Blog the Quality it Deserves – Just a blog :)
  7. 10 Tips to Make Your WordPress Blog Outstanding - JustAnART
  8. Popular WordPress Tips for Beginners
Leave a Comment
You may use: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .

CommentLuv badge


Kim Woodbridge is an accomplished Information and Technical Consultant specializing in the entire implementation of a WordPress based website including installation, theme design, upgrades, unique customizations and ongoing site maintenance.

Recent Comments

    • Property Marbella: Hi Kim, Good article with several good tips, my friend up in Sweden has clothing stores and online sales with little tr...
    • Kim Woodbridge: This post was written 2.5 years ago. At that time people wanted detailed instructions and asked me to write it. And wh...
    • Kim Woodbridge: Pretty much all themes have a page.php file. Are you using a child theme? If so, you will want to look for the
    • Mitch: That's why the internet has evolved into a worthless piece of "junk yard". Everybody is repeating the same thing over an...
    • Meredith: This is very straightforward info, and I think it will help, but I have one question. What if I don't have a page.php fi...

Wordpress Services

  • Installation, upgrades and maintenance
  • Conversion of existing html and css templates
  • Theme and plugin recommendations
  • CSS customizations
  • Troubleshooting and tweaks for unique situations
  • Customization for individual blogging goals and needs
  • Training and advice