- Published by
- Posted on
- 4 Comments
Ok so today I came across a client who wanted to show their recent posts in the sidebar but only from a specific category. I completed the job and later thought to myself that this might be very useful to the Webdevtuts community so I decided to write a quick tip for you guys. In this quick tip you will learn how to show your recent post from a specific category using a simple WordPress hack.
Copy and paste the code below and I will explain it below.
<?php $recent = new WP_Query("cat=26&showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>
So basically the code above is telling WordPress to get category 26 most recent post and to show 10 post at the max(Can be higher or lower). To make the code work you will need to place it inside of a ul and li tag. Hope this works for you all. If you have a question leave a comment below and I will answer them.