2017-07-31 137 views
0

此代碼來自shopify,但是,我想知道如何使默認排序選項爲「最新到最舊」,現在它是「A-Z」。這是針對沒有集合的頁面,因此它不會從集合頁面上已選擇的選項拉取。更改Shopify主題中的默認過濾器

<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> 

回答