Claes Gustavsson
Claes Gustavsson

Reputation: 5669

Shopify - how to select all products in a specific collection?

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.

Upvotes: 5

Views: 12642

Answers (1)

Steph Sharp
Steph Sharp

Reputation: 11682

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.

Upvotes: 9

Related Questions