问题描述
我的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 %}
似乎有效的新代码:
<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>
解决方法
我希望它设置如下内容:
<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>