Hi,

In many cases we do require to display the recent posts from a specific category… for that we need to modify the sidebar.php file of the current active theme and replace code as this:

Original Code:
<h2>Recent Posts</h2>
<ul>
<?php get_archives(‘postbypost’, 10); ?>
</ul>

Replace it with:

<ul>
<?php $recent = new WP_Query(“cat=4&showposts=10″); while($recent-
>have_posts()) : $recent->the_post();?>
<li><a href=”<?php the_permalink() ?>” rel=”bookmark”>
<?php the_title(); ?>
</a></li>
<?php endwhile; ?>
</ul>

Where is says cat=4 to insert the number assigned to the category that you want to display the posts from. You can find this from your Manage -> Categories page. You can also adjust the number of posts to be displayed where it says showposts=10.

This could be useful to someone who wants to display the most recent few posts from a few different categories in their sidebar.

Thanks,

Shane G.

Popularity: 7%

Related posts:
  1. Code To Display Recent Posts In WordPress Blog Hello All, In order to display recent posts of wordpress...
  2. Code To Display Scheduled Posts In Wordpress Blog Hi, This is the code to display scheduled posts in...
  3. Code To Display Recent Entries of Posts In Wordpress Blog Hi, Please ise this code to display recent entries...
  4. Code To Find List Of Posts Which Has No Tags In Wordpress Blog Hi, In order to find and display the untagged posts...
  5. Code To Display Recent Twitter Entry In WordPress Blog Hello All, In order to display recent twitter entry in...

Comments in this topic:

  1. Wordpress Blog Services - How To Display Most Commented Posts In Wordpress Blog Says:

    [...] Code To Display Recent Posts from Specific Categories In Wordpress Blog Hi, In many cases we do require to display the… [...]

Leave a Reply

You must be logged in to post a comment.