Skip to content

Instantly share code, notes, and snippets.

@Chrisedmo
Created July 31, 2012 11:35
Show Gist options
  • Save Chrisedmo/3216374 to your computer and use it in GitHub Desktop.
Save Chrisedmo/3216374 to your computer and use it in GitHub Desktop.
Shopify: Client-side sorting for collections
.reorder-drop-down {
margin-top:10px;
padding:10px;
overflow:hidden
}
.reorder-drop-down label {
display:inline;
}
jQuery('#reorder-options').change(function() {
var old_url = '{{ collection.url }}';
var new_url = old_url.replace(/(alpha-asc|alpha-desc|best-selling|created-desc|created-asc|price-desc|price-asc)/, jQuery(this).val());
window.location.href = new_url;
});
<div class="reorder-drop-down">
<label>Reorder this collection</label>
<select id="reorder-options" name="reorder-options">
<option value="alpha-asc"{% if collection.handle contains 'alpha-asc' %} selected="selected"{% endif %}>Alphabetically: A-Z</option>
<option value="alpha-desc"{% if collection.handle contains 'alpha-desc' %} selected="selected"{% endif %}>Alphabetically: Z-A</option>
<option value="best-selling"{% if collection.handle contains 'best-selling' %} selected="selected"{% endif %}>By Best Selling</option>
<option value="created-desc"{% if collection.handle contains 'created-desc' %} selected="selected"{% endif %}>By Created Date: Newest to Oldest</option>
<option value="created-asc"{% if collection.handle contains 'created-asc' %} selected="selected"{% endif %}>By Created Date: Oldest to Newest</option>
<option value="price-desc"{% if collection.handle contains 'price-desc' %} selected="selected"{% endif %}>By Price: Highest to Lowest</option>
<option value="price-asc"{% if collection.handle contains 'price-asc' %} selected="selected"{% endif %}>By Price: Lowest to Highest</option>
</select>
</div>
@jenna324
Copy link

jenna324 commented May 3, 2013

I used this codes but it doesn't work on my site.

What is the reason ?

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