How to display all posts in a category in WordPress sidebar

Had a few requests by clients to do this and the code is pretty simple:

<li id="recent-posts">
<h2>Our services</h2>
<?php query_posts('category_name=abc123&showposts=10'); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>  </li>
<?php endwhile; ?>

Replace abc123 in the example above with your actual category name (the “slug”) and change the amount after “showposts” to the desired quantity you wish to display.

Be the first to share this!

Leave a Reply

Your email address will not be published. Required fields are marked *