WordPress Snippet: Complete List of Posts

  1. query_posts($query_string.'posts_per_page=-1');
  2.        while(have_posts()) {
  3.        the_post();
  4.        the_time();
  5.        the_title();
  6. }

This will display the time and title for all your posts. This could result in a very long page, and a more usable way of doing it would be to change the posts_per_page parameter, and add Next and Previous links to navigate the whole list. Code snippet by Otto in the wp-hackers mailing list.

5 comments

  1. Ben Tremblay

    Yaa … great example of "snippet".

    You've got me redthinking my Codex page on "The Loop" … granularity … a ton of good links to a ton of good pages, but it's all too massive.

    Now, a collection of snippets ordered by funtionality or hooks or something … /that/ would be neat!

  2. Lorelle

    Brilliant, as usual. Is there a way to set this by category rather than date? That would be really useful.

  3. John A. Bilicki III

    Lorelle, you can add categories, find the number or name of your category on a category link and then check out this page…
    http://codex.wordpress.org/Template_Tags/query_posts#Category_Parameters

    I'm actually having a little trouble getting all the posts to display from 2008…

    1. query_posts('posts_per_page=-1'&'year=2008');

    When I designate the poss_per_page alone it will display all the posts I've made since I started my blog…but that defeats the purpose of specifying a year! Ideas?

  4. John A. Bilicki III

    I was adding extra quotes where it's more like an HTTP query…

    1. query_posts("posts_per_page=-1&year=2008");
  5. Kitkat

    Thanks for the tips. I was looking for a way to display all the posts on a blog of mine, this helps a lot!

Comments are closed.