Shopify隐藏畅销书

Shopify隐藏畅销书,shopify,liquid,Shopify,Liquid,我试图隐藏竞争对手观看畅销书的权限,特别是使用如下URL: www.store.myshopify.com/collections/all?sort_by=畅销书 我尝试过{%if collection.url包含'sort\u by=best-selling'%},但这不起作用。是否有任何方法可以将附加的查询字符串作为URL的目标 若否,有何建议? 谢谢 不幸的是collection.url没有返回查询字符串,在您的示例中,它将输出/collections/all 我认为在Liquid中没有办

我试图隐藏竞争对手观看畅销书的权限,特别是使用如下URL:

www.store.myshopify.com/collections/all?sort_by=畅销书

我尝试过
{%if collection.url包含'sort\u by=best-selling'%}
,但这不起作用。是否有任何方法可以将附加的查询字符串作为URL的目标

若否,有何建议?


谢谢

不幸的是
collection.url
没有返回查询字符串,在您的示例中,它将输出
/collections/all

我认为在Liquid中没有办法获取当前url查询字符串。您只能使用
collection.default\u sort\u by:“price”
或者使用
{%assign products=collection.products | sort:'price'%}

您可以使用jQuery覆盖
sort\u by
query字符串参数,用
price
替换
best-selling

<script type="text/javascript">
    $.urlParam = function(name){
        var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
        return results[1] || 0;
    }

    var sort_by = $.urlParam('sort_by');
    if(sort_by == "best-selling") {
        var url = window.location.href;
        url = url.replace("best-selling", "price"); // override to sort by price
        window.location.href = url; // redirect to url
    }
<script>

$.urlParam=函数(名称){
var results=newregexp('[\?&]'+name+'=([^&\]*)).exec(window.location.href);
返回结果[1]| | 0;
}
var sort_by=$.urlParam('sort_by');
if(排序依据==“畅销书”){
var url=window.location.href;
url=url.replace(“畅销书”、“价格”);//覆盖按价格排序
window.location.href=url;//重定向到url
}
在示例中使用此代码,它会自动将页面
www.store.myshopify.com/collections/all?sort_by=best-selling
重定向到
www.store.myshopify.com/collections/all?sort_by=price


但请记住,您的竞争对手可能会禁用该JS代码,但仍然可以访问最畅销的商品。

不幸的是
collection.url
不会返回查询字符串,在您的示例中,它会输出
/collections/all

我认为在Liquid中没有办法获取当前url查询字符串。您只能使用
collection.default\u sort\u by:“price”
或者使用
{%assign products=collection.products | sort:'price'%}

您可以使用jQuery覆盖
sort\u by
query字符串参数,用
price
替换
best-selling

<script type="text/javascript">
    $.urlParam = function(name){
        var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
        return results[1] || 0;
    }

    var sort_by = $.urlParam('sort_by');
    if(sort_by == "best-selling") {
        var url = window.location.href;
        url = url.replace("best-selling", "price"); // override to sort by price
        window.location.href = url; // redirect to url
    }
<script>

$.urlParam=函数(名称){
var results=newregexp('[\?&]'+name+'=([^&\]*)).exec(window.location.href);
返回结果[1]| | 0;
}
var sort_by=$.urlParam('sort_by');
if(排序依据==“畅销书”){
var url=window.location.href;
url=url.replace(“畅销书”、“价格”);//覆盖按价格排序
window.location.href=url;//重定向到url
}
在示例中使用此代码,它会自动将页面
www.store.myshopify.com/collections/all?sort_by=best-selling
重定向到
www.store.myshopify.com/collections/all?sort_by=price

但请记住,您的竞争对手可能会禁用该JS代码,并且仍然可以访问最畅销的商品