Vous n’avez pas besoin de requêtes personnalisées ou d’appels à la base de données pour obtenir une liste des articles récents. En fait, il y a une fonction intégrée dans WordPress qui fait exactement cela. Elle s’appelle wp_get_archives(). Vous pouvez reconnaître cette fonction comme un moyen d’afficher les archives mensuelles, mais avec quelques paramètres, vous pouvez la modifier pour afficher une liste d’articles WordPress récemment publiés. Voici le code :
<?php wp_get_archives('title_li=&type=postbypost&limit=10') ; ?>
Cela va supprimer tout formatage ajouté par WordPress et produire une belle liste des 10 derniers articles, chacun dans sa propre balise <li>.
How about displaying recent posts, together with a set number of characters from the actual entry?
Awesome bit of code! Only took me two years to find it. xD
LOL…better late than never.
Hi How do I make the list have the url’s inside Header tags?
Thanks
I need to exclude posts from a certain category, how could be done?
You’d need to make a custom loop and exclude the category. See the query_posts page for more info.
Thanks, this helped me a ton. 🙂
How can I do this with categories ?
You mean a list of categories or a list of posts from a certain categories?
For a list of categories you could use wp_list_categories.
For a list of posts from a certain category you would probably need a custom query. How to do that would need a new tutorial post entirely, but this should get you started.
clean and simple. Cheers for the code
@Corey: Not with this code, you would probably need to make a custom loop for that.
THANK YOU!!!! been wrestling with several recent post plugins but there was always something needing to be configured, edited, etc finally can remove all of the extra garbage needed to make them work
Can you put time and date to this? If so how?
It’s just working fine for me. Thanks for this excellent hack 🙂
Thanks! Just what I needed 😉
eh thanks.
what should I do to add a header to the lists?
thanks again.
Thanks a bunch, worked beautifully!
How about a version where you exclude certain categories from the recent posts? this function doesn’t allow the exclusion of categories. I am using it inside the loop before the call for the actual post title in a lefthand sidebar and found that the other version of a custom database query fed the last post title into the main post the_title(). If I use the version you supplied then it doesn’t feed the wrong title to the post but I can’t exclude a few custom categories that feed my news and portfolio.
This is perfect! Exactly what I needed to show the most recent posts in a church website’s main page design. Thanks so much for the tip!
I hope it can works in my blog
[…] full article –> The Easy Way To Display Recent Posts in WordPress | Theme Lab Tags: recent posts, WordPress Posted under: WordPress Subscribe to this […]
good ways~!
Yea i know that 🙂 I didnt say it was lol 😛
Anywhoo. Nuff said
@Anto: I am sure there is as I have implemented that at almost all the blogs I have designed, but what I meant was that it is not done on the way the archive is done. 🙂
Told ya BANAGO, there is 😛
I know its not as easy, but it would help people. I remember how to do it now.
There is a way actually, not as easy as this though. I’ll make a post soon about doing recent comments.
I don’t think this can be done for comments.
You should do the same for recent comments 😛