2016-05-16 127 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位之前)。順便提一下,另一種解決方案是在主題設置中添加產品選擇並顯示它。或者另一種方式:鏈接列表。 –

相關問題