Shopify:隐藏缺货的动态链接

Shopify:隐藏缺货的动态链接,shopify,liquid,shopify-template,Shopify,Liquid,Shopify Template,我在我的shopify网站上有下面的代码,目前它所做的只是显示一个指向“库存”或“全部显示”的链接。我想使链接更具动态性,因此,如果有人已按某个产品进行筛选,他们单击“库存”链接,它将仅显示该产品的库存。 例如,如果他们在单击链接后位于/collections/all/Product1,则应转到/collections/in stock/Product1 我当前的代码: <div class="filter-stock"> {% if page_title con

我在我的shopify网站上有下面的代码,目前它所做的只是显示一个指向“库存”或“全部显示”的链接。我想使链接更具动态性,因此,如果有人已按某个产品进行筛选,他们单击“库存”链接,它将仅显示该产品的库存。 例如,如果他们在单击链接后位于/collections/all/Product1,则应转到/collections/in stock/Product1

我当前的代码:

<div class="filter-stock">
{% if page_title contains "Products" %}
            <a href="/collections/in-stock"><b>Hide 'Sold Out' items</b></a>
{% endif %} 
{% if page_title contains "IN STOCK" %}
            <a href="/collections/all"><b>Show All Products</b></a>
{% endif %}

{%如果页面标题包含“产品”%}
{%endif%}
{%如果页面标题包含“库存”%}
{%endif%}
似乎有效的新代码:

<div class="filter-stock">
    {% if current_tags %}
        {% for tag in current_tags %}
            {% if collection == blank or collection.handle != 'in-stock' %}
                <a href="/collections/in-stock/{{ tag | handleize }}"><b>Hide 'Sold Out' items</b></a>
            {% endif %} 
            {% if collection and collection.handle == 'in-stock' %}
                <a href="/collections/all/{{ tag | handleize }}"><b>Show All Products</b></a>
            {% endif %}
        {% endfor %}
    {% else %}
        {% if collection == blank or collection.handle != 'in-stock' %}
            <a href="/collections/in-stock"><b>Hide 'Sold Out' items</b></a>
        {% endif %} 
        {% if collection and collection.handle == 'in-stock' %}
            <a href="/collections/all"><b>Show All Products</b></a>
        {% endif %}
    {% endif %}
</div>

{%if当前_标记%}
{当前_标记%中标记的百分比}
{%if collection==空白或collection.handle!='在库存“%”中
{%endif%}
{%如果库存“%”中的collection和collection.handle=='
{%endif%}
{%endfor%}
{%else%}
{%if collection==空白或collection.handle!='在库存“%”中
{%endif%}
{%如果库存“%”中的collection和collection.handle=='
{%endif%}
{%endif%}

我会让它设置如下:

<div class="filter-stock">
    {% if collection == blank or collection.handle != 'in-stock' %}
        <a href="/collections/in-stock{% if product %}/{{ product.handle }}{% endif %}"><b>Hide 'Sold Out' items</b></a>
    {% endif %} 

    {% if collection and collection.handle == 'in-stock' %}
        <a href="/collections/all{% if product %}/{{ product.handle }}{% endif %}"><b>Show All Products</b></a>
    {% endif %}
</div>

{%if collection==空白或collection.handle!='在库存“%”中
{%endif%}
{%如果库存“%”中的collection和collection.handle=='
{%endif%}

谢谢,我已经使用您发布的一些代码更新了上面的代码,这些代码似乎运行得很好,如果有任何关于提高效率的建议,我将不胜感激。