0
votes

I'm trying to add the most popular products from my client's Shopify store on her home. So I heard what you do is create a collection (I called mine Most Popular) and then use the following code to display the products:

<div class="product span4">
    {% assign best = collections["most-popular"] %}
        <ul>
            {% for product in best limit:10 %}
                <li><a href="{{ product.url }}">{{ product.title }}</a></li>
            {% endfor %}
        </ul>
  </div>

Simple, but didn't work. Just got a blank box with nothing in it. Anyone know the proper code for displaying items in my collection?

1

1 Answers

0
votes

Just try this code it will call products from collection named Most Popular

<div class="product-sec">


<ul>

 {% for product in collections.most_popular.products limit: 4 %}    <!--/*********** most_popular is name under collections limit is uded to show no. of products ******/ -->
           <li><a href="{{ product.url}}"><img style="width:177px;height:177px;" src="{{ product.featured_image | product_img_url: 'medium' }}" alt=""></a></li>
     {% endfor %}
  </ul>
  <span><a href="{{ shop.url }}/collections/most-popular">Most Popular</a></span>

I hope it will help you