How to display products of certain collections on a page?

3loow16
New Member
11 0 0

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.

0 Likes
Speedimize
Shopify Partner
300 48 145

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.

      <div class="product-item">
        <img src="{{ product.featured_image | product_img_url: 'medium' }}" alt="{{ product.title | escape  }}" />    
        <a class="shop-now" href="{{ product.url }}">{{ product.title | escape  }}</a>      
      </div>
    {% 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.

We Speedimize your store
Have a problem with speed performance, send me email here: hello@speedimize.io


If our advice was helpful please LIKE or ACCEPT SOLUTION
3loow16
New Member
11 0 0

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.

0 Likes
Speedimize
Shopify Partner
300 48 145

Thanks for getting back to me, 

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

{% if page_title == 'Fashion' %}
      <a href="{{ collection.url }}">
        <img src="{{ collection.products.first.featured_image }}">
        {{ collection.products.first.title }}
      </a>
{% elsif page_title == 'Services' %}
{% endif %}

 

Hope that helps you. 

We Speedimize your store
Have a problem with speed performance, send me email here: hello@speedimize.io


If our advice was helpful please LIKE or ACCEPT SOLUTION