WordPress: List Posts For A Category

As part of my site redesign I wanted to be able to list the latest articles for a specific category. Since I finished my category moves quicker than expected it was time to get on this task.

Quick Bits - WordPress category tileAs part of my site redesign I wanted to be able to list the latest articles for a specific category. Since I finished my category moves quicker than expected it was time to get on this task. I found the solution at (anti) social development. In short, the code to do it is:

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

The above example shows the last 5 articles in my “Mac OS X” category. Unless I’ve changed the site yet again you’ll see the code in action for the “Latest Mac Articles” over on the right. And the other “Latest…” lists are just variations on the theme. If you want more or less articles then change the number after showposts=.

The WordPress Codex has more category options on the reference page for the query_posts function.