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 |

63 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.

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. 30个优秀Wordpress技巧
  5. 30个优秀Wordpress技巧 | Yansen's Blog
  6. 30个优秀Wordpress技巧 | 半瓶可乐
  7. 激战的人生 » Blog Archive » 30个优秀Wordpress技巧
  8. 用友资讯 » Blog Archive » 30个优秀Wordpress技巧
  9. WP.ORG.CN | 30个优秀的Wordpress技巧
  10. 我要当站长–51dzz.com » 30个优秀Wordpress技巧
  11. 米老虎的BLOG » Blog Archive » 40+最有用的WordPress技巧
  12. PP BLOG# » Blog Archive » 30个优秀Wordpress技巧
  13. 9月森林 » 40+ Most Wanted Wordpress Tricks and Hacks
  14. Más de 40 consejos y trucos para Wordpress
  15. 30个优秀Wordpress技巧 - 网络应用与资讯
  16. 40 consejos y trucos Wordpress para dar a tus proyectos aspectos realmente diferentes. « Xyberneticos
  17. 40 consejos y trucos para Wordpress | aNieto2K
  18. 40 самых востребованных настроек/доделок/хаков для WordPress
  19. 40 Consejos y trucos para WordPress
  20. 40 trucos muy buenos para wordpress | Wotevar
  21. Mas de 40 trucos y hackeos para Wordpress | Pboza
  22. 40+ Most Wanted WordPress Tricks and Hacks | Blogging Tips
  23. Web Grafi 2.0
  24. 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.
  25. Dicas para você melhorar seu Blog - WordPress | DanielCamargo
  26. Cosas por hacer luego de instalar Wordpress | Durmiendo Afuera
  27. vsFish » 30个优秀Wordpress技巧
  28. 41 trucos y consejos para Wordpress « Helektron.com
  29. Antibioticos « SoLo Se Que No Se NaDa
  30. 鱼鱼小札 » Blog Archive » 30个优秀Wordpress技巧
  31. 30个优秀的WordPress技巧 | 智康博客--个人日记|网络技术|免费分享|技术交流|WordPress学习
  32. 30个优秀的Wordpress技巧为您打造强大的博客 | abe design studio
  33. 你不能不知道的30个优秀Wordpress技巧 | Idiigo.com
  34. Trucos y consejos para Wordpress | Seosistems
  35. 谷歌客 » 30个优秀Wordpress技巧
  36. Los 40 trucos mas importantes de Wordpress « Camyna.com
  37. Más de 40 consejos y trucos para Wordpress « El Cubanito Web
  38. WordPress 常用技巧40+则,诚邀您的参与翻译 - WordPress中文站
  39. 25 WordPress Tricks and Plugins to Make Your Blog Stand Out | Oragle
  40. Nightless Castle:::奈特丽斯城堡 » Blog Archive » 在Wordpress中显示指定分类的最新文章
  41. 30个优秀Wordpress技巧 | T.E.M.P
  42. Wordpress Hacks, Guides and Tricks | TechnoBuzz.net

Leave a Comment

Name:

E-Mail :

Website :

Comments :

Advertisement
Advertisement
Advertisement

Search

Donate

Please donate ReadyWPThemes

paypal

ADD TO FAVORITES

Add to Technorati Favorites