fahirsch asked: “How to list ALL posts on a 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!

Related Posts

Related Posts

No related posts.

22 Responses

Nov 20 2008 11:30

thankx
but i have wordpree in a Host
and it looks that this recipe works for blog who lucated on wordpress.com , am i right?
how can i add the archive page to my site?

Nov 20 2008 13:38

I have no clue if it should work on WordPress.com hosted blogs or not, sorry. The sure thing is that it works perfectly on self-hosted WP blogs ;)

Nov 20 2008 14:05

but i dont have any template page?
where is it?
i dont have any option when making a new page to set the page: select this page as a template

Nov 20 2008 15:37

If you’re on a self hosted blog, you have. Have you read the recipe linked from the post? When you’re creating a page, scroll down until you see “Page template”

Nov 25 2008 13:40

i finally did it right
but now i want to show the category of each post in front of the Title of the post
how can i do it?

Dec 05 2008 06:54

I used it on my site and it works beautifully. You still have to add the php calls for the header, sidebar and footer to the page template. I also changed the date format.

http://chrisberryonthe.net/all-posts-by-title/

Jan 22 2009 16:19

Nice solution! It worked fine for me. But a have lots of posts so I’ve got a very long page. I wanted to paginated this. Is it possible?

Jan 22 2009 18:18

@Piraua: I’m thinking about that too for my own archive page! I’ll try to find the solution when i’ll have the time.

Jan 22 2009 21:25

Great news!

I’ve keep on searching and got rewarded! I found this excelente solution about how to fix pagination on query_posts().

This solution solved my problem for good. I hope it also solve yours.

Here is the url for the solution:
http://www.michaelciccarelli.com/2008/07/fix-pagination-on-query-posts/

Feb 05 2009 17:42

great stuf! I’ve searched that long time – a simple approach to display kind of TOC of my blog. thank you!

Jun 10 2009 18:14

When I tried using this, my sidebar appears at the bottom of the new archive listing page. I’ve tried checking all the div tags and it all looks fine. Any suggestions? I’ve tried the code on this page and from here with the same results.

Jul 09 2009 17:43

Very useful. Thanks.

Aug 20 2009 14:02

cool
simple code – good result

Nov 18 2009 19:46

How can I alphabetize this list?

Nov 22 2009 10:54

How can I show it in alphabetical order??

Nov 22 2009 22:02

Here is the code for an alphabetized list of all the posts.

$myposts = get_posts(‘numberposts=-1&offset=$debut&orderby=title&order=asc&&exclude=107′);
foreach($myposts as $post) :

Nov 22 2009 22:04

Ignore the “exclude” statement.

Dec 12 2009 01:43

Can you code this loop inside the category loop?

Use case:
I want to show all posts in ASC or DESC order by date or title but have them first sorted by category without knowing the category number.

Cat1
post 1
post 2

Cat 2
post 1
post 2
post 3

Seems like you would need to have a primary loop that finds each category number and then run secondary loop that finds all the posts within that category…..

Idea on how to code that?

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required