How to display products of certain collections on a page?

How to display products of certain collections on pages like “fashion” or “services”?

Basically instead of having the collections listed on the pages, I want the products of the collections to be shown there.

Hi @3loow16

Aibek is here from Speedimize.io

Hope everything is fine on your end.

If this page has the .liquid extension, then you can display the products by adding the following code:

{% for product in collections.all.products %}
  {% for collection in product.collections %}
    {% if collection.title == 'CERTAIN_COLLECTION_TITLE' %}

-^Here you need to replace the name of the collection that you would like to display.


            
        {{ product.title | escape  }}      
      

    {% endif %}
  {% endfor %}
{% endfor %}

P.S We added HTML tags for an example, but you can write them in the form that is necessary for you.

Thank for the response!

I created the pages as “list-collections” template using the Pages section, so when I use your code it affects all the pages, the thing is I have pages like “Fashion” that have specific collections and another page like “Services” that have other collection.

Thanks for getting back to me,

In this case, you need to add a check to the page name:

{% if page_title == 'Fashion' %}
      
        
        {{ collection.products.first.title }}
      
{% elsif page_title == 'Services' %}
{% endif %}

Hope that helps you.

I tried this code for a collection which contains numerous products but it only showed 1 or 2 products.

A better way is like this:


{% assign collection = collections['clearance'] %}
{% for product in collection.products | limit: 4 %}
  
  {% render 'product-block', product: product %}
  
  ## {{ product.title }} - {{ product.price }}
{% endfor %}