问题描述
仅可在Shopify的收藏"页面上显示其他颜色变体.使用供应主题.我正在显示集合中的所有变体图像,但是如果存在变体,我只想显示颜色变体.有些项目没有变体,有些则有尺寸变体.有些具有颜色,有些具有大小和颜色.我不想在收集页面上显示颜色的所有尺寸变体.收集液
Goal to show just additional color variants on Collection page in Shopify.Using the Supply theme. I am displaying all variant images in collections, but would like to just display the color variant if variants exist. Some items have no variants, some have size variant. Some have color, and some have size and color. I do not want to show all size variants for a color on the collection page.Collection.liquid
{% for product in collection.products %}
{% for variant in product.variants %}
{% if has_sidebar %}
{% assign grid_item_width = 'large--one-quarter medium--one-third small--one-half' %}
{% else %}
{% assign grid_item_width = 'large--one-fifth medium--one-third small--one-half' %}
{% endif %}
{% include 'product-grid-item' %}
{% else %}
<div class="grid-item">
<p>{{ 'collections.general.no_matches' | t }}</p>
</div>
{% endfor %}
{% endfor %}
</div>
product-grid-item.liquid
product-grid-item.liquid
<div class="grid-item {{ grid_item_width }}{% if sold_out %} sold-out{% endif %}{% if on_sale %} on-sale{% endif %}">
{%,如果sold_out%} {{'products.product.sold_out'| t}} {% 万一 %}我想我需要从if语句开始检查变体,然后为颜色添加forloop.{%为product.options中的选项%}{%如果option =='颜色'%}
{% if sold_out %} {{ 'products.product.sold_out' | t }} {% endif %}I am thinking I need to check start with an if statement checking for variants, then add a forloop for color.{% for option in product.options %}{% if option == 'Color' %}
任何帮助将不胜感激.
Any help would be appreciated.
推荐答案
类似的东西应该可以帮助您入门.
Something like this should get you started.
首先我们循环产品选项,然后说我们只想要颜色或颜色,然后循环遍历属于该选项的所有变体...获取颜色并创建带有标题的列表项.
First we loop the product options, then we say we only want colour or color, then we loop over ALL variants which belong to that option... grab the colours and create a list item with the title.
<ul>
{% for option in product.options %}
{% if option == "Color" or option == "Colour" %}
{% assign index = forloop.index0 %}
{% assign colorlist = '' %}
{% assign color = '' %}
{% for variant in product.variants %}
{% capture color %}
{{ variant.options[index] }}
{% endcapture %}
{% unless colorlist contains color %}
<li><span class="color-{{color | handle }}"><a href="{{variant.id}}">{{color}}</a></span></li>
{% capture tempList %}
{{colorlist | append: color | append: ' '}}
{% endcapture %}
{% assign colorlist = tempList %}
{% endunless %}
{% endfor %}
{% endif %}
{% endfor %}
</ul>
这篇关于Shopify在集合中显示颜色变体,但不显示尺寸变体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!