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!
22 Responses
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?
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
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
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”
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?
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/
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?
@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.
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/
great stuf! I’ve searched that long time – a simple approach to display kind of TOC of my blog. thank you!
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.
Very useful. Thanks.
cool
simple code – good result
How can I alphabetize this list?
How can I show it in alphabetical order??
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) :
Ignore the “exclude” statement.
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: