【问题标题】:Show only one product on page by specific tag in shopify在shopify中按特定标签在页面上仅显示一种产品
【发布时间】:2016-05-16 11:39:58
【问题描述】:
<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> 

我尝试下面的代码,但这也不起作用。

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

                    {% include 'dailydeal-countdown' %} 

          {% endif %}
      {% endfor %}

  </div>

我怎样才能只显示一个带有特定标签的产品??

【问题讨论】:

    标签: shopify product


    【解决方案1】:
     {% 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 %},它将只显示一个产品。

    【讨论】:

    • 我正在尝试 {% for product in collections.all.products %} {% if product.tags contains 'frontpagedeal' %} {% include 'dailydeal-countdown' %} {% endif % } {% endfor %} 但没有产品展示
    【解决方案2】:

    在您的第二个示例中,句柄始终为小写,因此:

    <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 种。理想情况下,像这样的“每日交易”将是一个智能集合,其中包括基于它们的产品是“首页交易”,您可以跳过标签检查。

    【讨论】:

    • 这个 250 限制是多少?
    • 我尝试了您的代码,但没有输出,我也尝试了,但没有显示 {% for product in collections.all.products %} {% if product.tags contains 'frontpagedeal' %} {% include '每日交易倒计时' %} {% endif %} {% endfor %}
    • 抱歉——限制是 50。我写的时候一定刚刚读过 250 的图像限制。 (或者什么——我相信有一个合理的解释:-)
    • 您需要告诉我们更多关于您的收藏是如何设置的。我的原件可以在 Daily Deals 中显示所有带有 frontpagedeal 标记的产品。除非标记的产品是集合中的第一个产品,否则 @mash-r's 将不起作用。我刚刚将我的固定为只显示一种产品。
    【解决方案3】:

    也许直接在商店管理中创建一个“销售集合”然后显示它会很有用。

    如果是给客户,你可以在主题中添加一个选项,让客户在主题设置中选择销售集合。

    【讨论】:

    • 不,我不想添加更多收藏,如“销售收藏”只是我想根据我的意愿在首页显示单个产品而不创建任何收藏,我从任何收藏中选择一个产品并显示在带有特定标签的首页。
    • 你好。 Shopify 将查询限制为每页 50 个产品。因此,在您的收藏中,如果产品是第 51 个或更多,则不会在循环中找到它。因此,解决方案是对集合进行排序以将产品放在第一位(或至少在第 50 位之前)。顺便说一句,另一种解决方案是在主题设置中添加产品选择并显示它。或者另一种方式:链接列表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多