Collections Banner/Link - Related Products

Below could will add collection's banner (image) with link to collection page.

Ideally placed in related-products.liquid file.

It will take the first collection the product is in and if there is an image for that collection it will add it to the page where this code is placed.

    {% for c in product.collections %}
      {% if forloop.index == 1 and c.image != blank %}
        <div class="test" style="margin-bottom: 40px;">
          <a href="{{c.url}}"><img src="{{ c.image | img_url: 'master' }}"></a>
        </div>
      {% endif %}  
    {% endfor %}

Leave a comment