WordPress Tips – Displaying Recent Post from a Specific Category

As you know we use :


<h2>Recent Posts</h2>
<ul>
<?php get_archives('postbypost', 6); ?>
</ul>

to show our recent posts. But how do we show recent posts from specific category ?

To do this we use :


<ul>
<?php $recent = new WP_Query("cat=1&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>

here cat=1 is our category ID number and showposts=10 is our recent posts from specific category count. When you add this code to your sidebar.php file, you have to check your specific category ID from you admin panel, manage, categories.

You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.

Powered by WordPress | AT&T Cell Phones for Sale at iFreeCellPhones.com | Thanks to PalmPreBlog.com, MMORPGs and Online Shopping