In my opinion, all blogs should have an archive page: It allows your readers to quickly browse your blog and find what they’re looking for, and this page is also very good for SEO.
Here’s how to create this page on a WordPress blog:
Archive WordPress Plugins
There’s many plugins which allows you to automatically create an archive page. The good thing is that you’ll have (almost) nothing to do, and the bad thing is that you will not be able to customize it a lot, or you’ll have to edit the plugin files, which is sometimes a bit too hard if you’re not a developer.
On my blog in French lyxia.org, I use the Smart Archives plugin. Even if it gives me satisfaction, the loading time of the page is very long due to the amount of posts to be displayed simultaneously.
If you want to use a plugin, you shall also give a try to Clean Archives, or Extended Live Archives, which allows numerous personalizations.
Do it yourself
WordPress allows you to create page templates, so it’s possible to create manually an archive page. This is what I chose to do on my blog in English, CatsWhoCode.com.
Before starting to code, you’ll have to choose between two different kinds of archive page. The first one will list all your posts, and will allow a direct access to every article you wrote. The only bad thing is that when your blog will have many posts, the list may be a bit too long.
The second template, which is better for blogs that have been online since more than one year, will list your posts monthly and by categories.
Your choice is made? So let’s go coding!
First we’ll have to create a new file and name it archives.php. At the beginning of the file, paste the following lines:
<?php /* Template Name: Archive page */ ?>
This php comment define a name for our template, and will later allows us to select it on WordPress Dashboard, when we’ll create a new page.
First template: Listing all posts
<?php
$posts_to_show = 100; //Max number of articles to display
$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=$posts_to_show&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; ?>
Second template: Archives by months and categories
<?php while(have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<h2>Categories</h2>
<ul><?php wp_list_cats('sort_column=name&optioncount=1') ?></ul>
<h2>Monthly Archives</h2>
<ul><?php wp_get_archives('type=monthly&show_post_count=1') ?></ul>
<?php endwhile; ?>
After you chose one of the templates I shown you above and pasted it to your archives.php file, you just have to upload it on your wp-content/theme/yourtheme/ directory.
Then, in WordPress dashboard, create a new page, name it “Archives” (or whatever you want) and select Archive page as page template.
That’s all! You now have an archive page, which is good for both your reader and search engines crawlers.















This doesn’t seem to work for me in wp 2.6. It only seems to show the last 8 posts.
same for me in 2.9…Emmy
For those who saw unexpected results when using the first template, the culprit is the set of SINGLE QUOTES. If you replace the SINGLE quotes with DOUBLE quotes in the get_posts() string, it’ll work.
PHP won’t evaluate the variable since it is within a single-quoted string. Thus (I believe I’m right about this), the get_posts() call defaults to show the number of posts configured in the “Blog pages show at most” field of the “Reading” section of the “Settings” subpanel.
Change this:
$myposts = get_posts(‘numberposts=$posts_to_show&offset=$debut’);
… to this:
$myposts = get_posts( “numberposts=$posts_to_show&offset=$debut” );
Thanks for this
thank’s for information
@Mac Tips: Try to set $posts_to_show =-1;
It do works perfectly on my blog.
Oh Mac Tips, btw, I LOVE your website
A Little Help Here.
What i do is;
1.Create archives.php and uploaded it to my template directory.
2. pasting the begining code archives.php
3. Pasting the second template to archives.php
4. Create Archives page.
But it shows blank page Here :
http://offshoreman.net/oil-gas-jobs/archives
The part that i dont understand is…
“Then, in WordPress dashboard, create a new page, name it “Archives” (or whatever you want) and select Archive page as page template.”
How to select Archive page as a page template?
I managed to get it to work. A little work around.
Thanks jbj. I’ve been a reader for catswhocode for a while.
@Sulaiman: You’re almost done. Read this post for more info about pages templates. I also think this image shall help you.
Good luck!
hi,
TQ, with that I manage to assign page template to my Archives page. But it is displayed not in a proper template format. Here is the Archives page
http://offshoreman.net/oil-gas-jobs/archives/
The page was displayed in a very plain. Whereby my template displayed my page as follow;
http://offshoreman.net/
Hope you understand my english….
BtW : you are the only WordPress related tips that i subscribe. Marvelous content!.
my bad for the previous post. go to http://codex.wordpress.org/Pages#Page_Templates
look for subject “Archives with Content”
look for code get header, and get footer, paste it just like in the example code.
The archive works, you just have to paste your header & footer info in order to have it working as the rest of your blog.
I should have told it in the article, but the code to paste depends of your theme.
Obviosuly Hack WordPress is probably one of the best WordPress tips sites available! But you should also check out <a href=”http://www.catswhocode.com”>my blog</a>, where I also provide WordPress tips and tutorials.
Hey! Thanks for the tips but I am having so much trouble trying to assign the template to the page! Can you help me? There is only, and nothing about page templates!:
Password Protect This Page
Page Parent
+ Page Slug
Page Slug
Page Order
Thank you!
Hi Jaime,
Did you read comment #7 and visited the links I gave? If yes, what’s your WordPress version?
Hey. Thanks for the quick response. I’m using v2.6 (latest version of WP). If you’d like me to take a screenshot I’d happily do so
thanks
Thanks a lot for this article, I just used it for making the archives on my site.
I did have a little trouble finding the ‘page template’ part when writing the page, but after I created the archives.php file it popped right up between ‘page parent’ and ‘page order’ in the ‘advanced options’ section. I don’t know if that helps you Jaime, but it seemed to happen that way for me.
Hy there. Thank you for the post.
I’m wondering how can i also add a days before links to posts.. like this one
http://indielabs.com/blog/archive/
Thanks a lot!
There is some mistake in headings of “Second template: Archives by months and categories”
Code – wp_get_archives(‘type=monthly&show_post_count=1′) is for Monthly Archives but heading is given Categories
Same is with Monthly archives but heading is given Catagory.
@ BlogsDNA – Good catch! I have updated the post.
nice tip.
I should make one for my blog now.
It is So and SEO Cool!
Thanks!
Thanks for this, should sort me out.
In case you haven’t noticed, wp_list_cats has been deprecated and replaced by wp_list_categories.
http://codex.wordpress.org/Template_Tags/wp_list_cats
ho ho ho..
finally i find my article that i loked for..
Thanks for your tip..
So now, I will use the archives.php file to make the archive page.
Would love to give it a try!
I tried this tutorial, it worked like a charm ! But it displays only 10 articles ! ?
Any idea ? To show all the posts ?
I tried the first template listing all posts.. you can check my archives now…
Try this.I think your problem will be solved.
Ctreate the custom Archive page for your blog
Hey I finally solved the problem.. now my archives is fine !
Thanks for this tutorial !
Hellow, I’m trying to show a bit of content as for each archive. So like the first 20 words of the article as well for each archive shown.
How would you go about coding that up?
1.Open the function.php file of your theme.Then copy the following code and paste there.
function excerpt($num) {
$limit = $num+1;
$excerpt = explode(’ ‘, get_the_excerpt(), $limit);
array_pop($excerpt);
$excerpt = implode(” “,$excerpt).”…”;
echo $excerpt;
}
function content($num) {
$theContent = get_the_content();
$output = preg_replace(’/]+./’,”, $theContent);
$limit = $num+1;
$content = explode(’ ‘, $output, $limit);
array_pop($content);
$content = implode(” “,$content).”…”;
echo $content;
}
Now Find Out the line containing the following code from the above which you created earlier.
/* :<a href=””> */
Replace it by
/* :<a href=””> */
Do not use /* */
For more details visit HERE
here the actual php code in the parts
Now Find Out the line containing the following code from the above which you created earlier.
/* : */
Replace it by
/* : */
Do not use /* */
is not appearing for the theme which is used by this site.
so please visit here for your exact solution
Used the Clean Archives plugin. Its very nice actually.
thanks so much, it works
Creating an archive page is important. Especially so your content can be at the fingertips of your readers. Thanks for the tutorial on setting one up. I’m going to have to add one to my blog.
Thanks for the tutorial, really helped me finally make an archive page! Quick and straight to the point!
can you suggest it for blogspot blogs too , that would be ausumn , i mean just like wordpress , by creating link to archieves
Great job explaining the lot, but, after creating an archives page which is sorted by month, i didn’t get any nice results. It sure shows the months and links, but when i go to a month, i’m being redirected to the front page, but the url shows something like site.com/2009/11, so there’s no content with posts from that month there. How do I do that? I’m kinda green on this topic, so some explanation would help me a lot! What i want is after someones goes to a month, a page with posts for that month is shown…
Thanks,helps a lot
Worked perfectly. Thanks for the info.
I know this post is a couple years old, but I wanted to thank for you giving us this information. Extremely helpful! I really appreciate it!
I had problems with the first hack as my archives page was displaying the amount of posts set in “blog pages show at most” in the reading settings. To fix delete:
Then change:
$myposts = get_posts(‘numberposts=$posts_to_show&offset=$debut’);
to:
$myposts = get_posts(‘numberposts=-1&orderby=post_date&order=DESC’);
This will display all your posts and will over ride the posts per page limit.
Tyron I’m having the exact same problem but your post says
“To fix delete:” and then its blank!!
What do I have to delete?
Thanks for posting this… and for everyone who added to the code in the comments. I was able to make my automatically updating archives page in a breeze with this (I was manually adding to it every time I posted before).
Cheers,
Jacob
In the middle of reading it – minor thing: it is archive.php not archives.php, right?