X

A maneira fácil de exibir posts recentes no WordPress

Você não precisa de consultas personalizadas ou chamadas ao banco de dados apenas para obter uma lista de posts recentes. De fato, há uma função incorporada ao WordPress que faz exatamente isso. Ela se chama wp_get_archives(). Talvez você reconheça essa função como uma forma de exibir arquivos mensais, mas, com alguns parâmetros, é possível modificá-la para exibir uma lista de posts do WordPress publicados recentemente. Aqui está o código:

<?php wp_get_archives('title_li=&type=postbypost&limit=10'); ?>

O que isso fará é remover qualquer formatação adicionada pelo WordPress e exibir uma boa lista das 10 publicações mais recentes, cada uma em sua própria tag <li>.

Comentários   Deixe uma resposta

  1. How about displaying recent posts, together with a set number of characters from the actual entry?

  2. Gary David Hill abril 5, 2010 em 6:15 am

    Awesome bit of code! Only took me two years to find it. xD

    1. LOL…better late than never.

  3. Hi How do I make the list have the url’s inside Header tags?

    Thanks

  4. I need to exclude posts from a certain category, how could be done?

    1. You’d need to make a custom loop and exclude the category. See the query_posts page for more info.

  5. Thanks, this helped me a ton. 🙂

  6. How can I do this with categories ?

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

  7. clean and simple. Cheers for the code

  8. @Corey: Not with this code, you would probably need to make a custom loop for that.

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

  10. Can you put time and date to this? If so how?

  11. It’s just working fine for me. Thanks for this excellent hack 🙂

  12. Thanks! Just what I needed 😉

  13. eh thanks.
    what should I do to add a header to the lists?
    thanks again.

  14. Thanks a bunch, worked beautifully!

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

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

  17. I hope it can works in my blog

  18. The Easy Way To Display Recent Posts in WordPress | Anidan Design : eco-friendly web & graphic design junho 12, 2008 em 9:25 pm

    […] full article –> The Easy Way To Display Recent Posts in WordPress | Theme Lab Tags: recent posts, WordPress Posted under: WordPress  Subscribe to this […]

  19. good ways~!

  20. Yea i know that 🙂 I didnt say it was lol 😛

    Anywhoo. Nuff said

  21. @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. 🙂

  22. Told ya BANAGO, there is 😛

    I know its not as easy, but it would help people. I remember how to do it now.

  23. There is a way actually, not as easy as this though. I’ll make a post soon about doing recent comments.

  24. I don’t think this can be done for comments.

  25. You should do the same for recent comments 😛

Adicionar um comentário

Ficamos felizes por você ter optado por deixar um comentário. Lembre-se de que todos os comentários são moderados de acordo com nossa política de privacidade, e todos os links são nofollow. NÃO use palavras-chave no campo do nome. Vamos ter uma conversa pessoal e significativa.

WordPress Launch Checklist

A lista de verificação definitiva para o lançamento do WordPress

Compilamos todos os itens essenciais da lista de verificação para o lançamento de seu próximo site WordPress em um ebook prático.
Sim, envie-me o livro eletrônico gratuito grátis!