【问题标题】:How to display products from specific tag in shopify?如何在shopify中显示特定标签的产品?
【发布时间】:2021-10-08 12:43:22
【问题描述】:

如何在shopify自定义模板中显示特定标签“有机”的产品?这是我的代码。


{% if customer.tags contains 'organic' %}                    
<div class="product-list product-list--collection"> 
      {%- for product in collections.all.products  limit: product_limit-%}  
              {% for c in product.collections %}
          {% if c.title == collection.title %}
                              {%- render 'product-item' -%}  
            {% endif %}  
            {% endfor %}  
              {% if collection.handle=="all" %}
                           {%- render 'product-item' -%} 
                {% endif %}  
      {%- endfor -%}   
   </div>            
{% else %}
 <div class="product-list product-list--collection 
                                {% if has_filters %}
                                product-list--with-sidebar
                                {% endif %}">
                      {%- for product in collection.products -%}
                                  {%- render 'product-item' -%}
                      {%- endfor -%}   
   </div> 
{% endif %}

【问题讨论】:

    标签: shopify shopify-app shopify-template


    【解决方案1】:

    这将有助于显示特定的产品标题, 另请查看API documentation here

    {% for tag in customer.tags %}
      {% if tag == 'organic' %}
    
      {% assign collection = collections[my-collection-handle] %}
      
      {% paginate collection.products by 99 %}
      {% assign products = collection.products %}
    
      {% if collection.products.size > 0 %}
    
      {% for product in products %}
        {% for tag in product.tags %}
          {% if product.tag == 'limited_edition' %}
            <p>{{ product.title }}</p>
          {% endif %}
        {% endfor %}
      {% endfor %}
    
      {% endif %}
    
      {% endpaginate %}
        
      {% endif %}
    {% endfor %}
    

    【讨论】:

    • 我会删除 for tag in... 循环 - OP 的 if customer.tags contains ... 是针对这个特定问题的更高效的解决方案 :)
    【解决方案2】:
    {% for product in collections.all.products %}   
    {% if product.tags contains "organic" %} 
     {% include 'product-list-item' %}  
    {% endif %}
    {% endfor %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-28
      相关资源
      最近更新 更多