Jan 12

Wordpress Recent Posts from specific category

By hakan

As you know we use :


<h2>Recent Posts</h2>
<ul>
<?php get_archives('postbypost', 6); ?>
</ul>

to show our recent posts. But how do we show recent posts from specific category ?

To do this we use :


<ul>
<?php $recent = new WP_Query("cat=1&showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a></li>
<?php endwhile; ?>
</ul>

here cat=1 is our category ID number and showposts=10 is our recent posts from specific category count. When you add this code to your sidebar.php file, you have to check your specific category ID from you admin panel, manage, categories.

I hope it is work for you …


Topics: Worpress Tricks | 66 Comments »

66 comments | Add One

Comments

  1. Davinder - 01/28/2008 at 12:44 PM

    …nice tip. I will implement this and see how it goes… thnx

  2. Rajveer - 01/29/2008 at 5:00 PM

    Hey Friend thanks a lot for this mice tip, actually it’s very useful for a guy like me with not much knowledge of PHP stuff. So it really helped me a lot and indeed much better option than going for a separate plug-in installation.

    Keep the good work!

  3. hakan - 01/29/2008 at 5:43 PM

    Thanks for your interest…

  4. viettut.info - 02/6/2008 at 3:31 PM

    Can i show Recent Posts more than one category?

  5. hakan - 02/6/2008 at 4:57 PM

    Yes sure, just duplicate same loop with different category ID.

  6. Christine - 03/6/2008 at 5:08 AM

    Thank you! Exactly what I was looking for. Wanted to only list Recent Articles. So I used your code in a ‘php execute’ widget. Worked perfectly :)

  7. M - 03/6/2008 at 11:53 AM

    Great! Thank you!

    Is there anyway to include post images with this?

    Thanks a lot!

  8. Kjup - 03/14/2008 at 8:36 AM

    To list from more than one post you could do this:

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

    works like a charm. Thanks for the great update here!

  9. Kjup - 03/14/2008 at 8:37 AM

    Sorry, wouldn’t display all the code so here is the line: WP_Query(”cat=5,3,7,6,4&showposts=10″);

  10. web development blog - 03/17/2008 at 2:14 PM

    works perfectly thanks

  11. Rajveer - 03/24/2008 at 7:19 PM

    Hi,

    When Upload some pages like About or Contact, even that appears in the list.

    Is it possible to exclude few specified post so that they don’t appear?

    Thanks,
    Rajveer

  12. hakan - 03/24/2008 at 9:03 PM

    Hi Rajveer,

    I don’t have any idea about your question. As you see this method available to list all posts from specific category. You may check wordpress codex for your question.

  13. awal85 - 05/26/2008 at 11:29 AM

    thanks!

  14. Shira - 06/15/2008 at 8:29 AM

    this is wonderful, thank you so much..

    Do u by any chance know how to display all recent posts EXCEPT from a specific category?

    Thanks in advance

  15. hakan - 06/15/2008 at 11:06 AM

    @Shira,

    You can use Recent Posts widget(From WP Admin Panel =>presentation=>Widgets) for this.

  16. Steve - 06/16/2008 at 9:09 PM

    Shira was asking to display all posts EXCEPT one category. Is there any way of doing this? I’m looking for the exact same thing! Thanks!

  17. hakan - 06/17/2008 at 9:41 AM

    @Steve,

    Did you read my answer and try with Recent Post widget?

  18. Joe Everyman - 06/25/2008 at 5:07 PM

    This is just for your themes or can it work for any wordpress theme?

  19. hakan - 06/25/2008 at 6:01 PM

    yes, sure Joe…

  20. Marthin - 07/13/2008 at 11:14 PM

    how about open permalink in a new window? _blank :S

  21. Marthin - 07/13/2008 at 11:18 PM

    ah, got it. The error was some dumb letters :)

    <a href=”" target=”_blank” rel=”bookmark”>

    Note the target=”_blank” added.

  22. handan - 09/25/2008 at 7:32 AM

    great!

  23. MuneyMan - 02/1/2009 at 6:18 AM

    Thanks for sharing this!

  24. sq - 02/23/2009 at 6:35 AM

    Can’t get it to work with Wordpress 2.7.1, where do I get category ID’s ?

  25. 故事会 - 03/13/2009 at 1:56 PM

    故事会为您提供情感故事,成人故事,法制故事,恐怖故事,笑话故事,校园故事,儿童故事等分类故事!

  26. David - 03/17/2009 at 5:38 PM

    # sq – 02/23/2009 at 6:35 am

    Can’t get it to work with Wordpress 2.7.1, where do I get category ID’s ?

    If you go into the category you can see it in the URL after cat_ID=

  27. Wee - 03/19/2009 at 9:49 PM

    Great! Thanks a lot

  28. Bob - 04/24/2009 at 4:33 PM

    You alse can use the category name instead category ID number…

    I’ve tried it and it works…

    Thanks!

  29. Hanne Sena - 05/8/2009 at 6:23 PM

    great dude!!. this what im looking for. searching for about minutes just to get this code. thanx anyway

Trackbacks

  1. How To: Display the Recent Posts of Specific Categories
  2. 40+ Most Wanted Wordpress Tricks and Hacks
  3. 40+ Most Wanted Wordpress Tricks and Hacks | 胡作非为 - 每天精彩文章推荐 - Best Articles of the Day
  4. 9月森林 » 40+ Most Wanted Wordpress Tricks and Hacks
  5. Más de 40 consejos y trucos para Wordpress
  6. 40 consejos y trucos Wordpress para dar a tus proyectos aspectos realmente diferentes. « Xyberneticos
  7. 40 consejos y trucos para Wordpress | aNieto2K
  8. 40 самых востребованных настроек/доделок/хаков для WordPress
  9. 40 Consejos y trucos para WordPress
  10. 40 trucos muy buenos para wordpress | Wotevar
  11. Mas de 40 trucos y hackeos para Wordpress | Pboza
  12. 40+ Most Wanted WordPress Tricks and Hacks | Blogging Tips
  13. Web Grafi 2.0
  14. 40 Consejos para optimizar tu Wordpress » Comenta o Muere | Actualidad, Humor, Tecnología, Política, Ciencia, Música… y otros muchos temas de los que merece la pena hablar.
  15. Dicas para você melhorar seu Blog - WordPress | DanielCamargo
  16. Cosas por hacer luego de instalar Wordpress | Durmiendo Afuera
  17. 41 trucos y consejos para Wordpress « Helektron.com
  18. Antibioticos « SoLo Se Que No Se NaDa
  19. Trucos y consejos para Wordpress | Seosistems
  20. 谷歌客 » 30个优秀Wordpress技巧
  21. Los 40 trucos mas importantes de Wordpress « Camyna.com
  22. Más de 40 consejos y trucos para Wordpress « El Cubanito Web
  23. WordPress 常用技巧40+则,诚邀您的参与翻译 - WordPress中文站
  24. 25 WordPress Tricks and Plugins to Make Your Blog Stand Out | Oragle
  25. Wordpress Hacks, Guides and Tricks | TechnoBuzz.net
  26. WordPress 테마 제작에 필요한 snippet
  27. 블로그코디 » Blog Archive » Excellent WordPress Theme Resources
  28. Redbots » 30个有用的Wordpress技巧
  29. Top 30 Most Wanted Wordpress Tricks and Hacks | Make Money Blogging Experiment
  30. WordPress 常用技巧40+则 - 从1981年2月开始的人生
  31. 40 consejos y trucos para Wordpress | ProyectoAurora.com
  32. Cara Menampilkan Recent Post dari Kategori Tertentu « Belajar Wordpress
  33. 41 Wordpress Tricks & Hacks | Tips For Web Users
  34. Wordpress: 40 Trucos y Consejos para | ProyectoAurora.com
  35. 40+ Most Wanted Wordpress Tricks - o2webdev
  36. Wordpress Tricks and hacks of my choice | r_shahin : i am web designing
  37. Wordpress Tricks and Hacks « Online Free Applications Software Tips Tools Wallpapers

Leave a Comment

Name:

E-Mail :

Website :

Comments :

Advertisement
Advertisement
Advertisement

Search

ADD TO FAVORITES

Add to Technorati Favorites