4
嘿,我在我的shopify網站中使用布魯克林主題。我有不同的產品會變色。當我點擊收藏頁面時,我想將該產品的所有顏色變體顯示爲單獨的產品。我從昨天晚上開始使用Google進行搜索。在Shopify中使用布魯克林主題的集合頁面顯示所有顏色變體
嘿,我在我的shopify網站中使用布魯克林主題。我有不同的產品會變色。當我點擊收藏頁面時,我想將該產品的所有顏色變體顯示爲單獨的產品。我從昨天晚上開始使用Google進行搜索。在Shopify中使用布魯克林主題的集合頁面顯示所有顏色變體
看看下面的代碼。
<ul class="colorlist">
{% for option in product.options %}
{% if option == 'Color' %}
{% assign index = forloop.index0 %}
{% assign colorlist = '' %}
{% assign color = '' %}
{% for variant in product.variants %}
{% capture color %}
{{ variant.options[index] }}
{% endcapture %}
{% unless colorlist contains color %}
{% if variant.available %}
<li id="{{ variant.id }}" title="{{ variant.inventory_quantity }} In Stock" class="instock"><a href="{{ product.url | within: collection }}?variant={{ variant.id }}" style="background:{{ color | downcase }}">{{ color | downcase }}</a></li>
{% else %}
<li id="{{ variant.id }}" title="Out of Stock" class="outstock" >{{ color | downcase }}</li>
{% endif %}
{% capture tempList %}
{{colorlist | append: color | append: " " }}
{% endcapture %}
{% assign colorlist = tempList %}
{% endunless %}
{% endfor %}
{% endif %}
{% endfor %}
</ul>
上面的代碼可以顯示集合頁面中產品的可用顏色。您可以採用相同的循環結構並顯示整個產品網格,而不僅僅顯示變體名稱。
我在哪個文件中使用這個? – Ibrahim
你能幫我顯示整個產品網格嗎? – Ibrahim
我很樂意提供幫助。如果您正在使用網格佈局。你需要編輯Snippets/product-grid-item.liquid。這裏是要放置的代碼。 [鏈接](https://gist.githubusercontent.com/projoomexperts/793ee84852ff1528d8f051a08e954213/raw/fbbbe490303bf5c084eb3f1887cfb983eaf2f58a/product-grid-item.liquid) –