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

Last 5 posts in Tech

WordCount: 247
Gunning-Fog: 11.7348546191
Flesch-Kincaid: 9.60128082444
Flesch: 66.2201545823

5 Exigeses to “Blogger Hack: Alphabetizing Entry Index”

  1. Mark says:

    Is there a way to do this to our whole archives, or does this only work for what’s on our page now?

  2. John says:

    It works for any page…the main index page, or single archive pages, but it won’t create a listing of multiple archive pages.

  3. John says:

    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.

  4. Amit says:

    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

  5. Wade says:

    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.

Write a Midrash

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

You can add images to your comment by clicking here.