I’m still very new to Shopify so my knowledge of it is very limited.
I’ve created a page where I want to show certain products with the tag "export". These products should never come up on the collection page (siteurl/collection/all).
I’ve tried excluding the products with the tag from the collection template but that only leaves gaps on the pages its excluding.
This is my current code:
{% for product in collection.products %}
{% if product.tags contains 'export' %}{% continue %}{% endif %}
My code for displaying the product
{% endfor %}
I’ve also tried:
{% for product in collection.products %}
{% unless product.tags contains 'export' %}
My code for displaying the product
{% endunless %}
{% endfor %}
My thinking is that I’ll need to set the conditions before I call my products so my pagination doesn’t break. Is there a way to do this in Shopify?
2
Answers
What you need to know is that Liquid performs the initial action (
for product in collection.products
) before then performing the next one.So the forloop grabs all of the products, and then your
if
statement removes those products. Unfortunately, the pagination has already performed the product split during the forloop, so when you remove the product, it removes it from the paginated result.There is, annoyingly, no way around this.
The only realistic solution is to create your own
all
collection and then use smart filters to add everything except products tagged withxyz
.This code should work for you, it is rudimentary and includes some code that could be excluded but will help you understand how it works
CODE FOR YOUR COLLECTION TEMPLATE: