【发布时间】:2024-01-04 08:25:01
【问题描述】:
我的 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>
【问题讨论】:
标签: shopify liquid shopify-template