All tags of all collections

Highlighted
New Member
6 0 0

Hi,

I can access all tags *within a collection* via

 

{% for tag in collections.tags %}

But how do I get all tags of *all* collections (for my index page)?

Does anyone have an idea?

 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
5704 1 323

Hi Tim.

Here's one technique that will work no matter how many products you have in your store.

1. Click on the Collections tab in your admin. Create a new smart collection with title 'All' with the condition 'Product price is greater than 0'. Save.

2. In index.liquid, where you want to list your tags, paste this code:

{% assign collection = collections.all %}
{% paginate collection.products by 1000 %} 
<h3>All Tags</h3>
<div id="tags">{% if collection.tags.size == 0 %}
No tags found.{% else %}
{% for tag in collection.tags %}<a href="{{ collection.url }}/{{ tag | handle }}">{{ tag }}</a>{% unless forloop.last %}, {% endunless %}{% endfor %}
{% endif %}
</div>
{% endpaginate %}
0 Likes
Highlighted
Shopify Staff
Shopify Staff
5704 1 323

Sometimes this works too, when you don't have too many products:

{% assign collection = collections.all %}
<h3>All Tags</h3>
<div id="tags">{% if collection.all_tags.size == 0 %}
No tags found.{% else %}
{% for tag in collection.all_tags %}<a href="{{ collection.url }}/{{ tag | handle }}">{{ tag }}</a>{% unless forloop.last %}, {% endunless %}{% endfor %}.
{% endif %}
</div>

 

1 Like
Highlighted
New Member
6 0 0

Thank you!

0 Likes
Highlighted
Shopify Partner
1 0 0

Worked for me!

0 Likes
Highlighted
Shopify Partner
37 4 11

Nice @Caroline_Schnap as for ten years now, we only have this changed from this 

<a href="{{ collection.url }}/{{ tag | handle }}">{{ tag }}</a>

to this?

{{ tag | link_to_tag: tag }}

Or you would also optimise something else?

0 Likes