How to sort tags manually for a collection?

Highlighted
New Member
10 0 0

When tags are used for products in a collection, the default sort order used in the collections.liquid file is alpha a - z.  As we are using tags to separate our products into categories, and some collections cross different types of products, it results in an odd looking sort like this:

All Mountain Skis
Carving Skis
Men's Clothing
Powder Skis
Race Skis
Women's Clothing

What I want to do is to have the tags appear in a specific order (assuming that they are present of course) like this as it makes better sense for our products:

Race Skis
Carving Skis
All Mountain Skis
Powder Skis
Men's Clothing
Women's Clothing

I know that it's probably possible by editing the collections.liquid file, but if anyone has done this before successfully, it would help speed up the process rather than trying to figure it out myself, especially since our site is live :).

As we have a limited number of tags (around 10) we could probably even hard code the tags in building the select so long as it was possible to hide them when not present.

Any help would be greatly appreciated!
Mike

0 Likes
Highlighted
Shopify Partner
23 0 5

Hello Michael, have you got any solution? I'm also facing this problem. Any help will appreciate.

0 Likes
Highlighted
Tourist
14 0 1

A quick fix would be to add the code below in front of your tags like this:

Vendor_<span style="display: none">1</span>Nike
Vendor_<span style="display: none">2</span>Adidas
 

and you will get

Nike
Adidas

or

Size_<span style="display: none">1</span>XS
Size_<span style="display: none">2</span>S
Size_<span style="display: none">3</span>M

and you will get

XS
S
M

etc

What this code does is ad a number in front of your tag and also hides it. So add 1 for the first tag you want, 2 for the second etc.

Hope this helps.

Still have a problem with sorting filter groups though

Highlighted
Tourist
6 0 1

Excellent! I already have this piece of code from my theme at the sidebar__tag-list.liquid

 {% for tag in product.tags %}
          {% unless tag contains 'meta-' %}
            <li class="tag tag--{{ settings.tag_style }}">
              <a {% if current_tags contains tag %}class="is-active"{% endif %} href="{{ routes.collections_url }}/{% if collection.handle != blank %}{{ collection.handle }}{% else %}all{% endif %}/{{ tag | handleize }}">{{ tag }}</a>
            </li>
          {% endunless %}
        {% endfor %}

So I just need to put the number before the "meta-" like 0meta-tag1, 1meta-tag2... so it hides the entire tag on the page... 

0 Likes