This Blogger hack allows the monthly archive list, which might become very long if your blog, like mine, goes several years back, to be grouped by years. The listing will show the year of the current posting with expanded entries, and links to the other years. Clicking on another year will go to the latest posting page of that year, whith the monthly archive links expanded.
Additionnally, when looking at a previous post, the first link of the archive list allows you to go back to your most current posting.
<h2 class="sidebar-title">Archives</h2>
<ul class="archive-list">
<ArchivePage><li><a href="<$BlogURL$>">Publication actuelle</a></li></ArchivePage>
<script type="text/javascript">
var sCurrent=location.pathname;
if(sCurrent.indexOf("200")==-1){var dtNow=new Date();sCurrent=dtNow.getFullYear();}
else sCurrent=sCurrent.substr(sCurrent.indexOf("200"),4);
var archives=new Array();
<BloggerArchives>archives[archives.length]=new Array('<$BlogArchiveURL$>','<$BlogArchiveName$>');</BloggerArchives>
var sPYear="0000",bOpen=true,bClose=true;
for (var i=archives.length-1;i>=0;i--){
var sURL=archives[i][0],sYear=sURL.substr(sURL.indexOf("200"),4);
if(sYear==sCurrent){if(sYear!=sPYear&&bOpen){document.write("<li>"+sYear+"<ul>");bOpen=false;}document.write('<li><a href=\"'+sURL+'\">'+ archives[i][1].replace(sYear,"")+ '</a></li>');sPYear=sYear;}
else if(sYear!=sPYear){if(!bOpen&&bClose){document.write("</ul></li>");bClose=false;}document.write('<li><a href=\"'+sURL+'\">'+sYear+'</a></li>');sPYear=sYear;}
}
</script>
<noscript><BloggerArchives>
<li><a href="<$BlogArchiveURL$>"><$BlogArchiveName$></a></li>
</BloggerArchives>
</noscript>
</ul>
- Simultaneously publish Blogger to MSN Space
- Random quotes in sub-header
- Amazon recommended readings
See my other Blogger hacks:
Named one of the most influential industry contributors by the Digital Analytics Association. With over twenty years’ experience empowering organizations to analyze and optimize their online channels, Stéphane has cemented his position as a leading voice for online analytics and optimization.


5 comments:
I found your script very useful. I'm using it on my blog: http://asverderio.blogspot.com/
I only had to add an appendix after the "for" cycle, to close the list if the selected year is the oldest one.
One request: can you modify this script so that it will work even after 2010?
Can you help me, my date shows like this, how can I modify the code?
2009
* 1.11.
The code on on my blog and it should look like this:
2009
* december (3)
* november ( 10)
etc...
Can anyone help?
I had the problem of 2010 being displayed as a "1".
To make it work correctly change ever instance of "200" to "20".
You can see it working on my blog.
To restate Marcello's request, is there anyway you can post an updated code to fix the 2010 issue. Right now the code now shows a link for "1" where 2010 should be.
Thanks for the great easy-to-use code for this!
@ria: perfect. Thank you for the fix.
Post a Comment