Contents
This article will show you how to filter products and posts using tags.
Filter Products By Tag
To filter products by a certain tag, you can access the following path: shopname.com/collections/collection-slug/
Remember to replace “collection-slug” with the slug of the Collection you are testing.
Collection with only 1 tag
Template you need to edit: collection.liquid
/collections/collection-slug/tag
/collections/collection-slug/tag1+tag2
Filter Posts By Tag
Filter in 1 category only 1 tag
Template you need to edit: blog.liquid
/blogs/blog-category-slug/tagged/tag
/blogs/blog-category-slug/tagged/tag1+tag2
Process Data
Once you have visited such path, to create the filter you can do the following:
The current_tags
value is a collection of tags like Array so we can look up.
In case there is only 1 tag, you just need to call current_tags | first
is going out.
In case there are many tags, we will need to run through the loop:
{% for tag in current_tags %} {{ tag }} {% endfor %}
For example, an article needs to meet the criteria of having a tag to be displayed on that filter tag page
{% for article in blog.articles %} {% for tag in current_tags %} {% if article.tags contains tag %} {% include 'product-card' %} {% endfor %} {% endfor %} {% endfor %}
Below is the guideline for filtering articles, hope this guide help you