Wordpress - show posts from a particular category in sidebar "recent posts"
how can i make the "recent posts" in the WP sidebar show posts from a part开发者_开发问答icular category only?
Probably easiest to make your own recent posts widget with one of Otto's php code widgets http://wordpress.org/extend/plugins/php-code-widget/ and a new query:
<?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
<?php endwhile; ?>
Style it any way you want. The new query loop won't conflict with the main WP loop and can be used any numbers of time.
Or if you prefer something a little more user-friendly(doesn't require posting code into the widget), you may find the following plugin of use.
http://wordpress.org/extend/plugins/query-posts/
Nice little plugin that one, written by Justin Tadlock.
Just #FYI on both previous answers here: 'Otto's php code widgets' was last updated more than two years ago and has not been tested on the last 3 major Wordpress releases. Justin Tadlock's plugin also hasn't been tested on the last 3 major Wordpress releases.
At time of writing this update the recommended plugin is 'Category Posts Widget' by TipTopCopy, which was last updated approximately 2 weeks ago.
精彩评论