此代码来自shopify,但是,我想知道如何使默认排序选项为" 最新到最旧",现在它是&# 34; A-Z&#34 ;.这适用于没有集合的页面,因此它不会从集合页面上已选择的选项中拉出。
<div id="sort-by-menu">
<label for="sort-by">Sort by</label>
<select id="sort-by">
<option value="created-ascending">Oldest to Newest</option>
<option value="created-descending">Newest to Oldest</option>
<option value="best-selling">Best Selling</option>
<option value="manual">Featured</option>
<option value="price-ascending">Price: Low to High</option>
<option value="price-descending">Price: High to Low</option>
<option value="title-ascending">A-Z</option>
<option value="title-descending">Z-A</option>
</select>
</div>
<script>
Shopify.queryParams = {};
if (location.search.length) {
for (var aKeyValue, i = 0, aCouples = location.search.substr(1).split('&'); i < aCouples.length; i++) {
aKeyValue = aCouples[i].split('=');
if (aKeyValue.length > 1) {
Shopify.queryParams[decodeURIComponent(aKeyValue[0])] = decodeURIComponent(aKeyValue[1]);
}
}
}
jQuery('#sort-by')
.val('{{ collection.sort_by | default: collection.default_sort_by | escape }}')
.bind('change', function() {
Shopify.queryParams.sort_by = jQuery(this).val();
location.search = jQuery.param(Shopify.queryParams).replace(/\+/g, '%20');
});
</script>
答案 0 :(得分:0)
如果这是针对所有产品页面的话 https://yourdomain.com/collections/all
只需将链接更改为 https://yourdomain.com/collections/all?sort_by=created-descending
另外,你实际上可以创建一个名为&#34; All&#34;并控制排序。 如果您仍有疑问,请评论。