Each day we are born again. What we do TODAY is what matters most.
~Buddha
//Add this inside $(document).ready(function(){ //Find out if a category list exists on the page if( $('.postsbycategory-block').length != 0 ){ // Create empty array for later use var categories = []; // Loop through each list item and get its name $('.postsbycategory-block ul li').each(function () { categories.push({ categoryName: $(this).find('span.name').html(), listItem: $(this) }); }); // Sort the array by name categories.sort(function(a,b) { // Ensure a case-insensitive sort var c = a.categoryName.toUpperCase(); var d = b.categoryName.toUpperCase(); return (c > d) ? 1 : ((d > c) ? -1 : 0); }); // Loop though each in order and move to end of HTML list. // That way, the first alphabetically ends up on top $.each(categories, function(index, object){ object.listItem.appendTo(object.listItem.parent()); }); }
Each day we are born again. What we do TODAY is what matters most.
~Buddha