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.

Want automatic updates? Subscribe to our RSS feed or
Get Email Updates sent directly to your inbox!
Tweet This | Digg This | Stumble it | Add to Del.icio.us | | Print This

Jean-Baptiste Jung

Jean-Baptiste Jung is a 27 years old blogger/web developper/web designer who lives in the French-Speaking part of Belgium. Jean-Baptiste maintains two blogs: Cats Who Code where he and other authors write about Web Development, Web design, Blogging tips and WordPress, and WpRecipes where Jean shares useful WordPress snippets on a daily basis. When he's not blogging or having fun with codes, Jean loves to spend time with his wife and cat, and travelling everywhere he can.

There Are 37 Responses So Far »

  1. Mac Tips says:

    This doesn’t seem to work for me in wp 2.6. It only seems to show the last 8 posts.

  2. technology says:

    thank’s for information

  3. jbj says:

    @Mac Tips: Try to set $posts_to_show =-1;
    It do works perfectly on my blog.

  4. Oh Mac Tips, btw, I LOVE your website :)

  5. 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?

  6. Mac Tips says:

    I managed to get it to work. A little work around.

    Thanks jbj. I’ve been a reader for catswhocode for a while.

  7. jbj says:

    @Sulaiman: You’re almost done. Read this post for more info about pages templates. I also think this image shall help you.

    Good luck!

  8. 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!.

  9. 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.

  10. Jaime says:

    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!

  11. jbj says:

    Hi Jaime,
    Did you read comment #7 and visited the links I gave? If yes, what’s your Wordpress version?

  12. Jaime says:

    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

  13. Andy says:

    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.

  14. BOGDAN says:

    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!

  15. Blogsdna says:

    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.

  16. Kyle Eslick says:

    @ BlogsDNA – Good catch! I have updated the post. :)

  17. Bingu says:

    nice tip.
    I should make one for my blog now.

  18. RocyHua says:

    It is So and SEO Cool!
    Thanks!

  19. Donal says:

    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

  20. zulva says:

    ho ho ho..
    finally i find my article that i loked for..

  21. Iwan Susanto says:

    Thanks for your tip..

    So now, I will use the archives.php file to make the archive page.

  22. VirginTech says:

    Would love to give it a try!

  23. 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…

  24. Hey I finally solved the problem.. now my archives is fine ! ;)

    Thanks for this tutorial ! :)

  25. justin says:

    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?

  26. Softslas says:

    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

  27. cory says:

    Used the Clean Archives plugin. Its very nice actually.

  28. Xiawa says:

    thanks so much, it works :D

  29. 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.

  30. Thanks for the tutorial, really helped me finally make an archive page! Quick and straight to the point!

  31. Ajinkya says:

    can you suggest it for blogspot blogs too , that would be ausumn , i mean just like wordpress , by creating link to archieves

  32. Annelies says:

    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…

  33. frePerl says:

    Thanks,helps a lot

  34. knowledge says:

    Worked perfectly. Thanks for the info.

  35. Comet says:

    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!

Trackbacks/Pingbacks »

Tweetbacks »

Leave a Reply