Blogger Hack: Alphabetizing Entry Index
This code will take all the entries on the page and list them in alphabetical order, creating an index. This can be useful, for example, if your blog is a series of book/movie reviews, and you title your entries with the title of the books/movies. It’s less important to the reader, in this instance, what date the review was posted on than the subject of the review.
It is based upon the code Blogger has on its help pages to list the archive links on the main page in reverse chronological order.
Place the code in the sidebar of your template, using <MainOrArchivePage>, <ArchivePage>, or <MainPage> tags to indicate which pages you want indexed.
Here is the code:
<ul class=”archive-list”>
<script type=”text/javascript”>Â
var archives = new Array();
function mysortfn(a,b) {
if (a[1]<b[1]) return -1;
if (a[1]>b[1]) return 1;
return 0;
}
<Blogger>
<BlogItemTitle>
archives[archives.length] = new Array(’<$BlogItemNumber$>’, ‘<$BlogItemTitle$>’);
</BlogItemTitle>
</Blogger>
archives.sort(mysortfn);
for (var i=0;i<=archives.length-1;i++)
{
document.write(’<li><a href=”http://transylvaniandutch.com/td/wp-admin/post.php#’ + archives[i][0] + ‘”>’ + archives[i][1] + ‘</a></li>’);
}
</script>
</ul>
An example of the results of this code can be viewed at comicspoilers
Last 5 posts in General
- Alice's Restaurant - November 27th, 2008
- November 21: Other Reasons to Celebrate - November 21st, 2008
- November 14: Reasons to Celebrate - November 14th, 2008
- Both Twitter and Bloglines are down - November 13th, 2008
- Everythings gonna be all right - October 19th, 2008
Last 5 posts in Tech
- IT Flashback - October 9th, 2008
- Website Stats - October 8th, 2008
- The Importance of Backup - September 13th, 2008
- ThinkGeek Product of the Day - August 1st, 2008
- Windows 3.11 will soon cease to exist - July 11th, 2008
WordCount: 247
Gunning-Fog: 11.7348546191
Flesch-Kincaid: 9.60128082444
Flesch: 66.2201545823





11/18/2005 - 16 Heshvan, 5766 at 10:52 am
Is there a way to do this to our whole archives, or does this only work for what’s on our page now?
11/18/2005 - 16 Heshvan, 5766 at 11:02 am
It works for any page…the main index page, or single archive pages, but it won’t create a listing of multiple archive pages.
11/18/2005 - 16 Heshvan, 5766 at 11:21 am
If you want to place it on just your index page enclose the code within <MainPage> and </MainPage> tags.
If you want it just on your archive pages enclose the code between <ArchivePage> and </ArchivePage> tags.
If you want it on both, enclose the code between <MainOrArchivePage> and </MainOrArchivePage> tags.
3/13/2007 - 23 Adar, 5767 at 2:55 pm
Hi John,
Thanks for this hack, which will be useful to me. I was wondering if there is a way to show titles with a certain tag. For example, I may have movie and book reviews, and I would like to have two drop-down lists - one for movies, and one for books. How would I include the titles with a particular label? label = “book review”, or label = “movie review”)
Thanks a lot!
-Amit
1/5/2008 - 27 Tevet, 5768 at 10:02 am
I would really appreciate it if you could tell me what the first two or three lines of code in the New Blogger template to search for that this needs to go after. I have done some HTML but the code in the templates on Blogger is greek to me.