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!
category, quick tip, recent post wordpress, recent post wordpress tutorial, specific, Wordpress, wordpress snippet.
4 Responses to WordPress: How to show most recent posts from a specific category
-
-
have_posts()) : $recent->the_post();?>
<a href="” rel=”bookmark”>should do it, i changed the
(“cat=26&showposts=10″)
to
(“showposts=10″)
-
-
Hello.
I have tried 4 ways of doing this. They all work perfectly! love it

I have a post shown in my header from my music section. It shows the latest track we have online.This works – untill its a new day. Then the post is just gone. Don’t understand
Yea, I’ve a question.
Let’s say you wanted to use this on the home page to pull posts from but wanted it to be all of your recent posts as opposed to a single category. how would that look?
J