<$BlogRSDUrl$>

Thursday, January 12, 2006

Blogger Template Tip -- Reversing Archive Order 

In watching my statcounter I've come to notice a pattern. Almost every day, someone comes to my front page, and then checks out my oldest archive, the February 2005 collection of posts. The sad thing is, that archive has only one post, the first one -- and it isn't even particularly good.

I was puzzled, why the consistent interest in that old useless archive? Was it some sort of historical inquiry into how it all began? Do people want to know what my writing was like before the fame and fortune took its toll?

But more importantly, I wanted them to try some of my other writing, more recent stuff I've done after the fame and fortune took its toll. Maybe they would find something they'd like, something that justified coming back for another look.

Finally I figured out why it was happening: because on blogspot, the blogger template tags spit out your archives in oldest-first order so that your oldest writing is the first link people see. Oddly enough, my oldest writing is the last link I want people clicking on.

I decided to reverse the order of my archives, so my newest stuff came first. But I couldn't find a built-in blogger way to do this. So I "hacked" it by adding a little javascript around the archive list portion of my template. Here is what it looks like in my template, in case you want to try it:

<h6>ARCHIVES</h6>
<ul>
  <script type="text/javascript" language="JavaScript">
<!--
    var myLinks = new Array();
<BloggerArchives>
    myLinks.push(
      "<a href='<$BlogArchiveURL$>'><$BlogArchiveName$></a>"
    );
</BloggerArchives>
    var arch;
    var myReversedLinks = myLinks.reverse();
    for (arch in myReversedLinks)
    {
      document.write(
        "<li>"+
        myReversedLinks[arch]+
        "</li><br/>"
      );
    }
//-->
  </script>
  <noscript>
<BloggerArchives>
    <li>
<a href='<$BlogArchiveURL$>'><$BlogArchiveName$></a>
  </li>
</BloggerArchives>
  </noscript>
</ul>
If you try this, remember to copy your original template aside first, in case you need a safe version to fall back on. You might have to tweak what I've done a little to fit the way your template lists your archives, but it shouldn't be too hard.

Hopefully now I'll see people happily cruising my latest work, and that old, first post will remained buried, where it belongs, at least until my obligatory first anniversay post. And hopefully I haven't scared away my audience with this geekly outburst.

UPDATE: Jan 16--added script comments and a noscript tag to support non-javascript enabled browsers. Also located blogger support for reverse order archives does exist.

Technorati Tags: , , , , , ,

If you really, really liked this -- or even really, really hated it -- there's lots more:
ARCHIVES