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.
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!
4 Responses
Brilliant! Worked beautifully!
I was wondering how to get pagination to work within this page though… It didn’t work for me.
Cheers.
I’m having a problem with this one.
How can I use the template for a certain page?
@ Zul, @ Jasmin: Create a new page with “All posts” template
I am also trying to have listed all the posts from a specific category… please help me out!
Trackbacks: