Latest Articles & Tutorials

Don't be stingy, Share this post with others!

WordPress: How to show most recent posts from a specific category

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.

The Code

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.

Don't be stingy, Share this post with others!

Marcell Purham

Marcell is the founder of Webdevtuts. He is also a web designer & developer who loves to design and develop websites. If you're looking for him you can find him via @webdevtuts


More posts by Marcell Purham →
, , , , , , .

4 Responses to WordPress: How to show most recent posts from a specific category

Close