Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to alphabetically sort Shopify articles
<ul id="artists" class="medium-block-grid-4">
{% for artist in blog.articles %}
{% capture artist-name %}{{ artist.title | downcase }}{% endcapture %}
<li class="{{artist-name}}">
<a href="{{ artist.url }}">
<div class="artist-excerpt">{{ artist.excerpt }}</div>
<div class="artist-name">{{ artist.title }}</div>
<div class="country">{{ }}</div>
{% endfor %}
function sortArtists(id) {
function getLastName(artistElement) {
return artistElement.className.split(' ').splice(-1,1);
var dataTree = $('#' + id);
var artists = dataTree.children('li').get();
artists.sort(function(a, b) {
var lastNameA = getLastName(a);
var lastNameB = getLastName(b);
return (lastNameA < lastNameB) ? -1 : 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.