DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

One of my readers, fahirsch, asked how he can create a table of content for his WordPress blog. Here’s a simple code which can also be used to create an archive page.

To achieve this recipe, you first need to create a page template.
On this page template, paste the following code:

<?php
/*
Template Name: All posts
*/
?>
<?php
$debut = 0; //The first article to be displayed
?>
<?php while(have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<ul>
<?php
$myposts = get_posts('numberposts=-1&offset=$debut');
foreach($myposts as $post) :
?>
<li><?php the_time('d/m/y') ?>: <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php endwhile; ?>

Then, login to your WordPress dashboard, write a new page and select this page as a template. You’re done!

11 Comments

  1. Brilliant! Worked beautifully! :)

    I was wondering how to get pagination to work within this page though… It didn’t work for me. :(

    Cheers.

  2. I’m having a problem with this one.
    How can I use the template for a certain page?

  3. @ Zul, @ Jasmin: Create a new page with “All posts” template

  4. Niccolò Mineo

    I am also trying to have listed all the posts from a specific category… please help me out! :)

  5. the link to create “page template” is now broken btw.

  6. Hi,

    How do I create a page template to paste this code? The link within this guide no longer works?

    Thanks Jake

  7. Thanks for the tip, I just set up an “all posts” page with your help.

  8. If you would like to access some other post data like author, content or ID of your posts, you need to add “setup_postdata($post);” function to foreach loop, so it looks like this:

    foreach($myposts as $post) : setup_postdata($post);

  9. To create new page template
    copy your page template and add the following codes at the top of the page

  10. Thanks for this one, quick question, this works for all posts no matter the category, but if I need to link from the category page to this how can I have only the posts associated with that category?

  11. thanks for the tip. I was able to create the All Posts page, which is doing what I want. The only issue is the page does not contain any theme elements, it is just a white page with a list of posts. How do I get this list to show up within the main content area like the rest of the site?

    Thanks!

    Andy

Leave a Comment

Your email address will not be published. Required fields are marked *