Monday, January 31, 2005

Reverse Archive Listings Revisited

It’s easy this way. You don’t have to collect the lines in an array and physically writeln() them into the page; instead, shuffle the elements of the list that has already been loaded.

Here’s how: right after your archive list in your template, which should be between <MainOrArchivePage> </MainOrArchivePage> tags in your sidebar, insert this code immediately before the closing </MainOrArchivePage> tag:

<script type="text/javascript">
<!--
var a=getElementsByClass("archive-list");
var l=a[a.length-1].childNodes;
for (var x=0; x<l.length/2; x++)
{
var n=l[x].innerHTML;
l[x].innerHTML=l[l.length-x-1].innerHTML;
l[l.length-x-1].innerHTML=n;
}
/***************************************/
/* Old getElementsByClass() DEPRECATED */
/* -- see new post above. */
/***************************************/
function getElementsByClass(nm)
{
var n=new Array(0);
with(document)
{
for(var i=0; i<all.length; i++)
if(all[i].className==nm)
n.push(all[i]);
}
return n;
}

-->
</script>

This should reverse the order of your archives, so that the most recent appears and the top, and the least recent at the bottom. And that’s how you reverse your archives!

No comments: