Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carolineschnapp/355ed051c5a8962df599 to your computer and use it in GitHub Desktop.
Save carolineschnapp/355ed051c5a8962df599 to your computer and use it in GitHub Desktop.
Reorder tags inside groups when they contain numbers. Deal with number ranges (that is, a tag that contains two numbers), including price ranges that use a currency symbol. #Supply
<script>
$('.advanced-filters').each(function() {
var aNumber = /\d+/;
var myList = $(this).find('li');
myList.sort(function (a, b) {
a = parseInt( aNumber.exec( $(a).text() ), 10 );
b = parseInt( aNumber.exec( $(b).text() ), 10 );
if ( isNaN(a) || isNaN(b) ) {
return;
}
else {
return a - b;
}
});
$(this).append(myList);
});
</script>

What you want

You would like to re-order this:

Alt text

... so that it becomes that:

Alt text

You would also like to re-order this:

Alt text

... so that it becomes that:

Alt text

You don't always use numbers in your tags and so you don't want to mess with all those tags that don't contain numbers.

What you need to do

Open your collection-sidebar.liquid snipper in the online template editor, and, at the very bottom of the file, add the code shown below.

@aptbs85
Copy link

aptbs85 commented Oct 24, 2017

Do you know how to get the same result with text as well? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment