Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress - show posts from a particular category in sidebar "recent posts"

Tags:

wordpress

how can i make the "recent posts" in the WP sidebar show posts from a particular category only?

like image 452
pixeltocode Avatar asked Dec 17 '10 01:12

pixeltocode


People also ask

How do I show recent posts in sidebar in WordPress?

Use the Recent Posts widget. To start, choose Appearance > Widgets from your WordPress dashboard. Then, drag and drop the widget labeled Recent Posts into your sidebar.

How do I show related posts by category in WordPress?

You can find it in the Themename Options > Blog section. For this article, we used the Behold theme, where the option for showing related posts is called Enable Related Posts. After enabling the appropriate option, you should check for the appearance of the related posts section by examining one of your blog posts.

How do I show categories in WordPress sidebar?

In the WordPress sidebar, hover over Appearance and select Widgets from the pop-out contextual menu. Drag and drop the Categories widget from the list of Available Widgets on the left side of the screen into a location on the right side of the screen, such as Default Sidebar.


2 Answers

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.

like image 159
markratledge Avatar answered Nov 05 '22 19:11

markratledge


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.

like image 31
t31os Avatar answered Nov 05 '22 17:11

t31os