2016-05-16 126 views
0
<div class="row"> 
    {% for product in collections.all.products %} 
     {% if product.tags contains 'frontpagedeal' %} 
        {% if product.price_min < product.compare_at_price_min %} 
         {% include 'today-sale' %} 
        {% endif %} 
     {% endif %} 
    {% endfor %} 
    </div> 

我尝试在下面的代码,但这也不起作用。仅通过shopify中的特定标签在页面上显示一种产品

<div class="row"> 
      {% for product in collections.Daily_Deals.products %} 
       {% if product.tags contains 'frontpagedeal' %} 

        {% include 'dailydeal-countdown' %} 

      {% endif %} 
     {% endfor %} 

    </div> 

我怎么能只显示一个具有特定标签的产品?

回答

0
{% for product in collections.Daily_Deals.products %} 
    {% if product.tags contains 'frontpagedeal' %} 
     {% if forloop.first == true %} 
      {% include 'dailydeal-countdown' %} 
     {% endif %} 
    {% endif %} 
{% endfor %} 

你可以请测试这个,并告诉我,如果这是你想要的。

我所做的只是加入{% if forloop.first == true %} .... {% endif %}这将只显示一个产品。

+0

我想的是{%的产品在collections.all.products%} { 如果%含有product.tags 'frontpagedeal' %} {%包括 'dailydeal-倒计时' %} { ENDIF%%} {%endfor%}但没有产品展示 – user3436031

0

在你的第二个例子把手总是小写这样:

<div class="row"> 
{% assign oneShown = false %} 
     {% for product in collections.daily_deals.products %} 
      {% if oneShown %} 
      {% break %} 
      {% endif %} 
      {% if product.tags contains 'frontpagedeal' %} 
       {% include 'dailydeal-countdown' %} 
       {% assign oneShown = true %} 
      {% endif %} 
     {% endfor %} 
</div> 

应该工作。但是,如果您的收藏品包含超过50种产品,则可能找不到您正在查找的产品,因此您需要确保收集的产品少于50种。理想情况下,对于像这样的“每日特惠”,这将是一个聪明的收藏,其中包括基于它们的产品是'frontpagedeal',您可以跳过标签检查。

+0

这是什么250限制? – HymnZ

+0

我尝试了您的代码,但没有输出,我也试过,但没有显示{%collection.all.products%中的产品} {%if product.tags contains'frontpagedeal'%} {%include'dailydeal-countdown '%} {%endif%} {%endfor%} – user3436031

+0

抱歉 - 限制为50.我必须刚刚阅读250图片限制时,我写了。 (或者其他 - 我确信有一个合理的解释:-) – bknights

0

也许直接在商店管理中创建“销售收藏”并显示它会很有用。

如果是客户端,您可以添加一个选项到主题以允许客户端在主题设置中选择销售收藏。

+0

不,我不想添加更多的集合,如“销售集合”只是我想根据我的愿望在头版显示一个产品,而不创建任何集合,我从任何集合中选择一个产品,并在具有特定标签的首页展示。 – user3436031

+0

你好。 Shopify限制每页50个产品的查询。所以,在你的收藏中,如果产品是第51或更多,它将不会在循环中找到。因此,解决方案是对产品进行分类,以便将产品放在第一位(或至少在第50位之前)。顺便提一下,另一种解决方案是在主题设置中添加产品选择并显示它。或者另一种方式:链接列表。 –

相关问题