4
votes

I´m new to Shopify and I´m trying to get all the product images that I have added to a collection that I made and called "my catalog".

I have started with this, and it is looping through all the images, but how do I select only the ones with the collection "mycatalog"?

{% for product in collection.products %}

<div>
    <a href="{{ url }}">
      <div style="background-image: url('{{ product.featured_image | product_img_url: 'large' }}');"> </div>
</a>
</div>

  {% endfor %}

I have tested with some different things, but I can´t get it working!

An example would help a lot to understand how it works. Any input appreciated thanks.

1

1 Answers

7
votes

Try this:

{% for product in collections.mycatalog.products %}

<div>
  <a href="{{ url }}">
    <div style="background-image: url('{{ product.featured_image | product_img_url: 'large' }}');"> </div>
  </a>
</div>

{% endfor %}

See the Global variables page on the Shopify wiki for more info:

{% for product in collections.frontpage.products %}
   {{ product.title }} 
{% endfor %}

The liquid variable "collections" contains a list of all of the collections in a shop.