Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

shopify

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.

like image 804
Claes Gustavsson Avatar asked Mar 22 '23 21:03

Claes Gustavsson


1 Answers

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.

like image 126
Steph Sharp Avatar answered May 16 '23 08:05

Steph Sharp