2017-02-05 4 views
1

現在、私のBig Cartelサイトにカスタムページを作成しています。このページでは、特定のカテゴリ(シャツ、ジャケット、ジーンズ)の製品のリストを表示したいと思います。現在のコードは次のとおりです。特定のカテゴリを含むBig Cartelの製品ページを作成しますか?

{% for product in products %} 
    {% if forloop.first %} 
    <ul id="products" class="{% if forloop.length == 1 %}single_product{% endif %}{% if forloop.length == 2 %}double_product{% endif %}"> 
    {% endif %} 
    <li id="product_{{ product.id }}" class="product"> 
    <a href="{{ product.url }}" title="View {{ product.name | escape }}"> 
     <div class="product_thumb"> 
     <img src="{{ product.image | product_image_url | constrain: '560' }}" class="fade_in" alt="Image of {{ product.name | escape }}"> 
     </div> 
     <div class="product_header"> 
     <h2>{{ product.name }}</h2> 
     <span class="dash"></span>    
     <h3>{{ product.default_price | money_with_sign }}</h3> 
     {% case product.status %} 
     {% when 'active' %} 
      {% if product.on_sale %}<h5 class="mmi-accent">On Sale</h5>{% endif %} 
     {% when 'sold-out' %} 
      <h5 class="mmi-accent">Sold Out</h5> 
     {% when 'coming-soon' %} 
      <h5 class="mmi-accent">Coming Soon</h5> 
     {% endcase %} 
     </div> 
    </a> 
    </li> 
    {% if forloop.last %} 
    </ul> 
    {% endif %} 
{% endfor %} 

問題は現在、私が持っているすべてのカテゴリのすべての製品を示しています。

は、私がここに同様の質問を見てきました:How to use BigCartel "Variables" to Call Different Product Categories

それは開口部forループを編集することで、特定の単一のカテゴリにすべての製品から変更する方法を助言しました。したがって、次のようになります。

{% for product in categories.shirts.products %} 

これも、カテゴリ 'シャツ'製品リストのみを表示します。私は同じリストの中に「Jackets」と「Jeans」も表示したいと思います。これは可能ですか?

ありがとうございます。

答えて

1

私は最終的に問題を解決し、コードを変更しました。基本的にはのループを(または各カテゴリのループが必要)として作成します(ul内)。

相続人は完全なサンプルコード:

<ul id="products"> 

    {% for product in categories.jacket.products %} 
    <li id="product_{{ product.id }}" class="product"> 
    <a href="{{ product.url }}" title="View {{ product.name | escape }}"> 
     <div class="product_thumb"> 
     <img src="{{ product.image | product_image_url | constrain: '560' }}" class="fade_in" alt="Image of {{ product.name | escape }}"> 
     </div> 
     <div class="product_header"> 
     <h2>{{ product.name }}</h2> 
     <span class="dash"></span>    
     <h3>{{ product.default_price | money_with_sign }}</h3> 
     {% case product.status %} 
     {% when 'active' %} 
      {% if product.on_sale %}<h5>On Sale</h5>{% endif %} 
     {% when 'sold-out' %} 
      <h5>Sold Out</h5> 
     {% when 'coming-soon' %} 
      <h5>Coming Soon</h5> 
     {% endcase %} 
     </div> 
    </a> 
    </li> 
    {% endfor %} 

{% for product in categories.dress.products %} 
    <li id="product_{{ product.id }}" class="product"> 
    <a href="{{ product.url }}" title="View {{ product.name | escape }}"> 
     <div class="product_thumb"> 
     <img src="{{ product.image | product_image_url | constrain: '560' }}" class="fade_in" alt="Image of {{ product.name | escape }}"> 
     </div> 
     <div class="product_header"> 
     <h2>{{ product.name }}</h2> 
     <span class="dash"></span>    
     <h3>{{ product.default_price | money_with_sign }}</h3> 
     {% case product.status %} 
     {% when 'active' %} 
      {% if product.on_sale %}<h5>On Sale</h5>{% endif %} 
     {% when 'sold-out' %} 
      <h5>Sold Out</h5> 
     {% when 'coming-soon' %} 
      <h5>Coming Soon</h5> 
     {% endcase %} 
     </div> 
    </a> 
    </li> 
    {% endfor %} 

    {% for product in categories.baby-grow.products %} 
    <li id="product_{{ product.id }}" class="product"> 
    <a href="{{ product.url }}" title="View {{ product.name | escape }}"> 
     <div class="product_thumb"> 
     <img src="{{ product.image | product_image_url | constrain: '560' }}" class="fade_in" alt="Image of {{ product.name | escape }}"> 
     </div> 
     <div class="product_header"> 
     <h2>{{ product.name }}</h2> 
     <span class="dash"></span>    
     <h3>{{ product.default_price | money_with_sign }}</h3> 
     {% case product.status %} 
     {% when 'active' %} 
      {% if product.on_sale %}<h5>On Sale</h5>{% endif %} 
     {% when 'sold-out' %} 
      <h5>Sold Out</h5> 
     {% when 'coming-soon' %} 
      <h5>Coming Soon</h5> 
     {% endcase %} 
     </div> 
    </a> 
    </li> 
    {% endfor %} 

</ul> 

希望誰に役立ちます。その後、アクティブなカテゴリを

{% for category in categories.active %} 
    {% if category.name contains 'jacket' or category.name contains 'dress' or category.name contains 'baby-grow' %} 
    <h2>{{ category.name }}</h2> 
    {% for product in category.products %} 
     <p>{{ product.name }}</p> 
     <img src="{{ product.image | product_image_url | constrain: '50' }}"> 
    {% endfor %} 
    {% endif %} 
{% endfor %} 

ループ、各カテゴリを表示するか、特定のカテゴリのいずれかに合致するかどうかを確認:

0

ここでは別の(DRY -er)方法です。はいの場合は、そのカテゴリの製品をループします。

関連する問題