How to Make a WordPress Archives Page

Tuesday 28 June 2005 @ 23:45 // Filed under Hacks, Usability, Web Dev, WordPress

By default, WordPress doesn’t seem to have an archives page. It just stacks up all your months of writing in the sidebar. This strikes me as an inelegant solution (interface clutter, anyone?) It also strikes me as a solution that does not scale well. I haven’t yet come across a WP site that’s been going for, say, five years (in fact I don’t think its been around anywhere near that long), but just imagine.

It’s actually remarkably easy to make your own archives page with the power of WordPress templates (AKA themes.) Being a little familiar with these helps, but is not necessary knowledge. You’ll also need to grab the Clean Archives plugin.

Begin by making the template for your archives page. Create a file named (say) archives.php in /wp-content/themes/currentThemeName/.

<?php
require('./wp-blog-header.php');
/*
Template Name: Archives Template
Description: A template for archives pages.

Note: requires Clean Archives plug-in
http://www.sporadicnonsense.com/2005/04/28/clean-archives-plug-in/
*/
?>

<?php get_header(); ?>

<h1>Archives</h1>

<!-- You may wish to add a search box here -->

<?php echo srg_clean_archives(); ?>

<?php get_footer(); ?>

The second and final step is to create the “page” in WordPress. Go into your WP admin area then Write > Write Page. Give it a title (eg. Archives.) Down in Page Options you will see Page Template. Select Archives Template, and click Create New Page.

Important! If you are using permalinks, make sure your .htaccess file is writable (eg. chmod 777 it) before doing the above step!

And that’s it. You should have a nice page like so. Remember to make sure it’s valid XHTML.

Acknowledgments: this post drew heavily on Secrets of WP Theming Part 1.

29 Comments — RSS

  1. Wicked, will have to do this for ACM when I have a chance. Thanks.

    Comment by Pete — June 29, 2005 @ 10:00 am

  2. Hey man,

    You know me so I went for “ok, two steps, done the first one, done second…what! doesn’t work… stuff it….”

    Perhaps I followed your steps too literally? I’m curious what ‘make-a-page’ does, does it literally make imapage.php somewhere or is it a bit more complicated than that?

    A.

    Comment by Azrael Montague — August 22, 2005 @ 5:40 pm

  3. It’s actually simpler than that. Make-a-page is just like make-a-post but without a date (so it doesn’t appear in your blog.) Instead, pages normally get listed on your sidebar.

    And that’s about all there is to say about that. Good luck!

    Comment by db — August 22, 2005 @ 7:43 pm

  4. Some more research, I think I have found the problem. It looks like your theme sucks. All the little problems with it drive me crazy. Maybe updating to the latest version will fix it?

    Comment by db — August 23, 2005 @ 12:02 am

  5. [...] Courtesy of db’s How To Make A WordPress Archives Page and some hand-coding by the man himself, Indeed, Discursive now has a Archives page. [...]

    Pingback by Indeed, Discursive - An understanding of life is required to live it well » Archives! — September 24, 2005 @ 2:14 pm

  6. Great post and works like a breeze. Check out my archives, although they are not five years. More like five days :)

    Comment by Martijn Stegink — December 1, 2005 @ 10:40 am

  7. Cheers mate. Nice wallpaper collection, I must say.
    http://www.bos89.nl/zp/wallpaper/

    Comment by db — December 2, 2005 @ 12:37 am

  8. Ok, I’ve got an archives page, though I found for some reason that I needed to hard-code the address of my wp-blog-header, I guess it was because it was in a different directory.

    I also managed to figure out how to add my two sidebars. But it’s still missing all the styling of my other pages. Presumably I need to put some code into the archives template to do this, but I can’t figure out what code. It’s not a biggee really, as I really just wanted to do this for the benefit of google.

    http://www.americascupmagazine.com/?page_id=235

    Thanks.

    Comment by Pete — January 9, 2006 @ 9:34 am

  9. Yeah, for whatever reason WP themes seem to be a bit messier than necessary. It’s possible just adding [div id="content"] and [/div] (with chevrons) will fix it – effectively you want to just copy the way it’s done in the index.php of your theme. But yeah – it works, and that’s the important thing.

    Comment by db — January 9, 2006 @ 1:15 pm

  10. If you’re reading this and wondering whether it’s worthwhile, I would give an enthusiastic “Yes!” My site hasn’t exploded in popularity, but hits and search hits are up and I’m also noticing higher rankings and hits especially from google. The archives page has received 17 hits this year, making it the fourth most popular page. Many hits are actually from search requests, so I’m very pleased I went to the effort. Cheers DB.

    PS. Do you have any idea why I might be getting a huge number of 404 errors on:
    /index.php/feed/

    Cheers

    Comment by Pete — February 10, 2006 @ 3:13 pm

  11. [...] I learned a few things while doing this rebuild so I want to give a plug to those places that taught me something. First the archives page was created thanks to the nice tip at db.rambleschmack.net. Secondly, I didn’t know how to pass multiple parameters into a wp function the way they want them but thankfully the wordpress codex page on wp_get_archives answered my question for me (pass them like URL arguments). [...]

    Pingback by rawlinson - us » Blog Archive » Site has a New and Darker Look — March 1, 2006 @ 11:35 am

  12. Thanks I’m using it now, greeting from IRAQ.

    Comment by Saif Al-Badri — March 25, 2006 @ 8:51 am

  13. Ahh, nice to have my archives 100% sorted. It turns out on p&m the archives weren’t anything like I thought they were (I can’t have looked at that page closely). I also sorted the formatting issues on ACM.

    I’ll explain the issue for anyone else as thick as me.

    You can pretty much copy the code from DB’s post for the archives template, but there’s one thing you need to do if you want the page formatted properly. You need to put the main part of the page (i.e. after the header and before the footer) into a div. So after the [?php get_header(); ?] put a line that says [div class="$$"]. To figure out what $$ should be, go to your index.php in the themes folder and find a line near the top that says exactly that. For instance, my two are “main-copy” and “columnwide” (from memory) for each of my blogs.

    You’ll then need to put a [/div] before the [?php get_footer(); ?] line. Then you should be sweet.

    DB, this is right aye?

    Comment by Pete — April 7, 2006 @ 3:21 pm

  14. Another thing, in the original post, you mentioned that this resolved issues of “interface clutter”.

    I’m not sure this resolution is completely problem solving though, as with 300 posts (exactly as of today), the ACM archives page is getting a bit unruly.

    It’s not going to be a nice scrolling experience when it gets to 1000 posts (which it should do easily before the 2007 America’s Cup.

    On the other hand, it’s and advantage having the full post titles there as users can always do a ‘find’ on specific words. I guess this is an ongoing debate.

    Comment by Pete — April 7, 2006 @ 3:26 pm

  15. With regards to comment #13: Yes, that is correct. Note that it varies a lot from theme to theme. For example, it works fine without anything on my theme, and many themes would probably want [div id="content"] (as noted in comment #9). Anyway, nice job Pete. Looking hot.

    And to comment #14: Again, correct. I have wondered about this myself, maybe showing just one year (month?) at a time would stop it getting crazy. But Hell, if it’s good enough for Daring Fireball, it’s good enough for me.

    Comment by db — April 7, 2006 @ 7:03 pm

  16. Ahhh, yes, that’s exactly what you said in comment 9. I don’t think I understood what you meant at the time, so hopefully I’ve added some value by fleshing it out some more. Cheers.

    Comment by Pete — April 8, 2006 @ 10:47 am

  17. In regards to my comment # 8 “for some reason that I needed to hard-code the address of my wp-blog-header”.

    If you do that, remember to change address if you switch web hosts and abandon the old domain. ;)

    Comment by Pete — August 18, 2006 @ 2:35 pm

  18. Installed the plugin, added the archives.php to my theme but when it says to select archive template in the template pulldown it’s not there. All I have is default, static page and single. Any ideas?

    Comment by Kelly — February 10, 2007 @ 6:45 am

  19. Hi there Kelly. What theme/version of WP are you using? It looks like they may have changed how templates work in v2/2.1. At any rate, it still works for me. I would suggest you double-check you have put the correct archives.php file into the correct folder (ie. of your current theme) on your server. Unfortunately I don’t spend much time working with WordPress at the moment so I can’t give you anything more expert than that. Let me know how it goes, I may have to look into updating this post.

    Comment by db — February 10, 2007 @ 12:03 pm

  20. [...] How to Make a WordPress Archives Page | db.rambleschmack.net [...]

    Pingback by Maxime Rousseau » Blog Archive » Creating Integral Wordpress Archives — February 21, 2007 @ 12:30 pm

  21. Your site is perfect!

    Comment by Lohness — May 13, 2007 @ 9:15 am

  22. Thank you!

    Comment by db — May 15, 2007 @ 8:15 pm

  23. Thanks for the info!

    Comment by Peyo — November 8, 2007 @ 8:42 am

  24. I tried as you suggest but under my “New Page” window i don’t see a page template option i have expanded all the windows and looked in custom fields, nothing…
    What do i do?

    Comment by glen stadig — September 6, 2008 @ 12:11 am

  25. glen: Are you sure you followed the instructions as above? My understanding is that the Page Template option does not appear until you put at least one file in your theme folder with the “Template Name” line (as in the example).

    Comment by db — September 6, 2008 @ 11:58 am

  26. Useful post, Dave. Nearly four years old and still relevant, that’s impressive!

    Comment by David Chambers — May 3, 2009 @ 3:43 am

  27. Hi Dave. I’ve written a PHP snippet to do away with the Clean Archives Reloaded plugin. People may find this useful:

    <?php global $post;
    $myposts = get_posts(’numberposts=-1′);
    $month_and_year = ”;
    if ($myposts) : ?>
    <ul class=”archives”>
    <li>
    <?php foreach ($myposts as $post) :
    $date = get_the_time(’j');
    if (get_the_time(’F Y’) != $month_and_year) : // we need to begin a new month…
    if ($month_and_year) : // by first ending the previous month if applicable… ?>
    </ul>
    </li>
    <li>
    <?php endif;
    $month_and_year = get_the_time(’F Y’); ?>
    <h3><?php echo $month_and_year; ?></h3>
    <ul>
    <?php endif; ?>
    <li class=”day-<?php echo $date; ?>”><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>
    </li>
    </ul>
    <?php endif; ?>

    See it in action at http://davidchambersdesign.com/archives/.

    Comment by David Chambers — June 16, 2009 @ 6:43 pm

  28. You have a kind face, especially your eyes. I think I can see your soul bouncing around in there!

    Comment by timberland custom booots — June 16, 2010 @ 11:45 am

  29. *blush*

    Such a nice thing to say, from someone who’s never seen my face.

    Comment by db — June 19, 2010 @ 1:54 pm

Sorry, the comment form is closed at this time.