One of the things I like most about WordPress is the ability to pretty much do anything you want with it. With the help of a plugin, or custom PHP code, you can accomplish most things. If you would like to display a list of recent posts from a specific category in your sidebar, follow the steps below:
Step #1
Download the PHP Code Widget created by Otto.
Step #2
Upload the plugin to the wp-content/plugins directory on your server and activate it from within the WordPress dashboard.
Step #3
Go to Appearance > Widgets screen in your WordPress dashboard and choose the PHP Code widget and place it into the appropriate widget area you wish to display the list.
Step #4
Copy the code below and paste it into the text box for the PHP Code widget.
<ul>
<?php $recent = new WP_Query("cat=3&showposts=5"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
Notes
You can specify the category you wish to display in the sidebar by replacing the cat=3 with the category ID you want to display. If you want to add/reduce the number of posts shown, simply change the showposts=5 to any number. The plugin/code has been tested with WordPress 2.8 and was successful.
Screenshot





This is great stuff! Very helpful and opens up more choices and flexibility in design.
Thanks for the helpful tip Brian!
Steve
Thanks, but I think, there is way better solution for everyone – Justin Tadlock’s Query Posts Plugin → http://justintadlock.com/archives/2009/03/15/query-posts-widget-wordpress-plugin
In widget settings you just use GUI to select category, number of posts and other query parameters and then you instantly go.
http://justintadlock.com/blog/wp-content/uploads/2009/03/query-posts-widget.png
I like the Category Posts Widget:
http://wordpress.org/extend/plugins/category-posts/
Why do all this coding if there’s already a great widget that accomplishes the same thing easily?