X

La façon la plus simple d’afficher les articles récents sur WordPress

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

Commentaires   laisser une réponse

  1. Ellery Davies mai 24, 2013 à 8:52 am

    I use the WordPress Twenty-Eleven theme and have always displayed recent posts using the widget in Jetpack. But I want this list to show in the individual posts as well. Is there a way to do this?

  2. Muchas gracias!!!! Thank you very much!!!! Just what I was looking for!

    Saludos desde Spain 😉
    Sara

  3. Thanks! That solved my problem in 2 seconds.

  4. Thanx Leland – just in the nick of time
    *Love ur site btw 😀

    M.?

  5. Sachin @ Web Design Mauritius mai 14, 2010 à 8:30 am

    I’ve implemented it on my about page here: http://www.webdesign-bureau-of-mauritius.com/web-design-mauritius

    It works like a charm. Thanks for this!

  6. Can you also tell the system to display the excerpt for the post? or just a teaser?

  7. Okay. All this code does is display a very simple list of recent posts. The markup is similar to this:

    <ul>
    <li><a href="http://example.com/recent-post-3">Latest One</a></li>
    <li><a href="http://example.com/recent-post-2">2nd Latest Post</a></li>
    <li><a href="http://example.com/recent-post-1">3rd Latest Post</a></li>
    </ul>

    If you want anything else (thumbnails, character counts, whatever) that would require a custom loop and I can’t really go over each specific case in the comments here.

  8. How do I do this and also have thumbnails? Very small thumbnails. 35px X 35 px. Google is annoying me sending me round in circles all day long. They’re useless lol.

    Well I await your useful reply.

    Thanks.

    1. Oh wow this is easy 😀 Thanks for this great article!

      BTW, has anyone come across functions to merge both recent post and page update in chronological order?

Ajouter un commentaire Annuler la réponse

Nous sommes heureux que vous ayez choisi de laisser un commentaire. N'oubliez pas que tous les commentaires sont modérés conformément à notre privacy policy, et que tous les liens sont en nofollow. N'utilisez PAS de mots-clés dans le champ du nom. Engageons une conversation personnelle et constructive.

WordPress Launch Checklist

L'ultime liste de contrôle pour le lancement de WordPress

Nous avons rassemblé tous les éléments essentiels de la liste de contrôle pour le lancement de votre prochain site Web WordPress dans un ebook pratique.
Oui, envoyez-moi le gratuit !