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.

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.

Joe Granados the author

Joe Granados is the owner 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
  1. Jimmy says:

    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

    • LJ says:

      have_posts()) : $recent->the_post();?>
      <a href="” rel=”bookmark”>

      should do it, i changed the
      (“cat=26&showposts=10”)
      to
      (“showposts=10”)

  2. Michael says:

    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 🙁

Leave a Reply