fahirsch asked: “How to list ALL posts on a page?”

November 20, 2008 at 8:47 am

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!