Here is the current code I'm using as my Blogger Archive Template. It is for a weekly archive. It
Update: That nice man Phil Ringnalda has done a lovely point'n'click Blogger Archive Script Generator based on some of this code. It's probably the best way to get this functionality if you're not a script monkey yourself. :-)
// AJB 28/10/2001 Better Archive Listings
// Update 31/10/2001, added short/long list with cookies
// 1/11/2001 Modified to default to "short" listing - duh!
// 2/11/2001 Added Next/Previous Archive Linking code
// 17/11/2001 Now Works in Opera
// todo: list
// Build a Link formatter
// (with different date formats, salvage code from w-of-w & .combots)
// Make Limit Rolling, so X around currently viewd archive
// are visible, not just the top X
// My Type 'ArchiveCookie'
function ArchiveCookie_GetCookie()
{
// Look for our named cookie
var i = document.cookie.indexOf( this.CookieName + "=" );
if ( -1 != i )
{
var e = document.cookie.slice( i ).indexOf( ";" );
this.cookieVal = document.cookie.slice( i+this.CookieName.length+1, (-1 != e)?e:document.cookie.length );
return this.cookieVal;
}
return null;
}
function ArchiveCookie_SetCookie( Value )
{
var expireDate = new Date();
expireDate.setTime( expireDate.getTime() + this.expireTimeInMs );
var cookietext = this.CookieName + "=" + Value +
"; expires=" + expireDate.toGMTString()+"; path=/";
document.cookie = cookietext;
this.cookieVal = Value;
}
function ArchiveCookie_KillCookie()
{
var expireDate = new Date();
document.cookie = this.CookieName + "=0" +
"; expires=" + expireDate.toGMTString();
this.cookieVal = null;
}
function ArchiveCookie_GetValue()
{
return this.cookieVal;
}
function ArchiveCookie( theCookieName, theExpireTimeInDays )
{
this.CookieName = theCookieName;
this.cookieVal = null;
this.expireTimeInMs = theExpireTimeInDays * 100 * 60 * 60 * 24;
// methods
ArchiveCookie.prototype.GetCookie = ArchiveCookie_GetCookie;
ArchiveCookie.prototype.SetCookie = ArchiveCookie_SetCookie;
ArchiveCookie.prototype.KillCookie = ArchiveCookie_KillCookie;
ArchiveCookie.prototype.GetValue = ArchiveCookie_GetValue;
}
// My Type 'ArchivePage'
function ArchivePage_MakeLink_UKShort()
{
var newName = this.StartDate.getDate()+"/"+(this.StartDate.getMonth()+1)+"/"+this.StartDate.getFullYear();
var outString = "";
if ( -1 != location.href.indexOf( this.Link ) )
{
// No Link, this is our page!
outString = newName;
}
else
{
// Link
outString = "<a href='" +
this.Link + "'>" +
newName + "</a>";
}
return outString;
}
function ArchivePage_MakeLink_Normal()
{
var outString = "";
if ( -1 != location.href.indexOf( this.Link ) )
{
// No Link, this is our page!
outString = this.Name;
}
else
{
// Link
outString = "<a href='" +
this.Link + "'>" +
this.Name + "</a>";
}
return outString;
}
function ArchivePage_Compare( rhs )
{
if ( this.StartDate == rhs.StartDate )
return 0;
else if ( this.StartDate > rhs.StartDate )
return 1;
else
return -1;
}
function ArchivePage( theLink, theName )
{
this.Link = theLink;
this.Name = theName;
// Extract Date from Name, Yuk!
// 09/30/2001 - 10/06/2001
this.StartDate = new Date( this.Name.slice(6,10), this.Name.slice(0,2)-1, this.Name.slice(3,5) );
this.EndDate = new Date( this.Name.slice(13+6,13+10), this.Name.slice(13+0,13+2)-1, this.Name.slice(13+3,13+5) );
// methods
ArchivePage.prototype.MakeLink_Normal = ArchivePage_MakeLink_Normal;
ArchivePage.prototype.MakeLink_UKShort = ArchivePage_MakeLink_UKShort;
ArchivePage.prototype.Compare = ArchivePage_Compare;
}
// Sort function
function bi_comp( a, b )
{
return -a.Compare( b );
}
// Short/Long listing selection
function ShowAll()
{
var cookie = new ArchiveCookie( "LimitArchive", 365 );
cookie.SetCookie( 0 );
location.href = location.href;
}
function ShowRecent( HowMany )
{
var cookie = new ArchiveCookie( "LimitArchive", 365 );
cookie.SetCookie( HowMany );
location.href = location.href;
}
// Previous/Next Archive Links
function FindIdx( myURL )
{
for ( var n=0; n<BlogInfo.length; n++ )
{
if ( -1 != myURL.indexOf( BlogInfo[n].Link ) )
return n;
}
return null;
}
function MakePreviousArchiveLink( myURL, AnchorText )
{
var idx;
if ( null == ( idx = FindIdx( myURL )) ) return null;
if ( 0 == idx ) return null;
if (( null == AnchorText ) || ( "" == AnchorText ))
return BlogInfo[idx-1].MakeLink_UKShort();
else
return "<a href='" + BlogInfo[idx-1].Link + "'>" +
AnchorText + "</a>";
}
function MakeNextArchiveLink( myURL, AnchorText )
{
var idx;
if ( null == ( idx = FindIdx( myURL )) ) return null;
if ( (BlogInfo.length-1) == idx ) return null;
if (( null == AnchorText ) || ( "" == AnchorText ))
return BlogInfo[idx+1].MakeLink_UKShort();
else
return "<a href='" + BlogInfo[idx+1].Link + "'>" +
AnchorText + "</a>";
}
function WriteArchiveSection( BlogInfo )
{
// Process & Output
BlogInfo.sort( bi_comp );
// Show Link for Home Page, if this is an archive Page
if ( -1 != location.href.indexOf( "blogarc" ) )
{
document.write( "<a href=\"./\">Current Posts</a><br><br>" );
}
// Next/Previous Links
var navlink="";
var wrotelink=false;
if ( navlink = MakeNextArchiveLink( location.href, "Previous Week" ))
{
document.write( navlink + "<br>" );
wrotelink=true;
}
if ( navlink = MakePreviousArchiveLink( location.href, "Following Week" ))
{
document.write( navlink + "<br>" );
wrotelink=true;
}
if ( true == wrotelink )
document.write( "<br>" );
// See If the user has an archive listing limit set
var limit = 0;
var limitArchiveCookie = new ArchiveCookie( "LimitArchive", 365 );
if ( null == limitArchiveCookie.GetCookie() )
limitArchiveCookie.SetCookie( defaultlimit );
limit = limitArchiveCookie.GetValue();
if (( limit > BlogInfo.length ) || ( 0 == limit ))
limit = BlogInfo.length;
// The Archives
for ( var n=0; n<limit; n++ )
{
document.write( BlogInfo[n].MakeLink_UKShort()+"<br>" );
}
// Archive Length Options
if ( 0 == limitArchiveCookie.GetCookie() )
{
document.write( "<a href=\"javascript:ShowRecent(defaultlimit);\">[Show only Recent]</a><br>" );
}
else
{
document.write( "<a href=\"javascript:ShowAll();\">[Show All]</a><br>" );
}
}
// Start Execution here....
// Blogger Populates Data here
var count=0;
var BlogInfo = new Array();
<Blogger>
BlogInfo[count++] = new ArchivePage( "<$BlogArchiveLink$>" , "<$BlogArchiveName$>" );
</Blogger>
// Other Data
var defaultlimit = 4;
// Do it
WriteArchiveSection( BlogInfo );