Monday, December 24, 2007

How To Sort The Labels Widget Reverse Alphabetically

Someone on the Blogger Help Group asked if it was possible to sort the Labels widget z to a rather than a to z, someone replied, "no". Of course, with JavaScript the answer is actually "yes".

You can see an example of this widget in the Compender Sandbox. Here's the code:

<b:widget id='ReverseLabels' locked='false' title='Reverse Alphabetical Labels' type='Label'>
<b:includable id='main'>
<b:if cond='data:title'>
<h2><data:title/></h2>
</b:if>
<div class='widget-content'>
<ul>
<script type="text/javascript">
/*
Reverse Alphabetical Tag Sort
by Raymond May Jr.
http://www.compender.com
Released to the Public Domain
*/
var root = "<data:blog.homepageUrl/>";
var tagUrl = "search/label/";
var labels = new Array();

<b:loop values='data:labels' var='label'>
labels.push("<data:label.name/>");
</b:loop>

i=labels.length;
while(i > 0)
{
i=i-1;
document.write("<li><a href='"+root+tagUrl+labels[i]+"'>"+labels[i]+"</a></li>");
}
</script>
</ul>
<b:include name='quickedit'/>
</div>
</b:includable>
</b:widget>

2 comments:

مهدی said...

hi
I am that person.
tanks a lot for your help.

Schweizer Ansichten alias Roger Rabbit said...

I got a problem. Let explain me.
On my music blog (http://metallschaedel.blogspot.com/) the tags/labels are the band names. Of course with the time the list is geting longer and longer.
A collegue of mine has changed alreade into clouds. But it's still not satisfying, means still to long.
My question now is as follows: Is it possible to create the labels as expanding character group. e.g. A-C, D-F etc?
As I'm not an expert in programming, I can't do it myself and need help. Thanks for any answer.

Post a Comment