What to display recent posts from a particular category in WordPress blog? Then you are right place.In this article I will show how to display posts in sidebar only from one category.First know How To Get Category ID for a Category Page In WordPress Blog.This category ID must be known to show posts on that category.
Now add the following code in Sidebar.php page,
<h2>Linux Posts</h2>
<?php $recent = new WP_Query(); ?>
<?php $recent->query(‘cat=19&showposts=5‘); ?>
<?php while($recent->have_posts()) : $recent->the_post(); ?>
<ul>
<li>
<a href=”<?php the_permalink(); ?>”>
<?php the_title(); ?>
</a>
</li>
</ul>
<?php endwhile; ?>
Note:
After getting your category Id you can coustamize the code,
<?php $recent->query(‘cat=19&showposts=5‘); ?>
Parameter cat indicates which category’s posts are shown. Parameter showposts is the number of posts to be displayed.
It’s very simple without using any plugin.Isn’t it? 😉