Shopify Filter By Unlimited Tags

Posted 2 months ago     313      filter tags shopify

This takes any tag that starts with 'brand-', adds it to a list to display, then either adds or removes from URL.


<details class="details-filter collection-filters"> <summary class="details-filter__summary filters-heading" role="button" aria-expanded="true"> <span class="filters-heading__heading">Brands</span> </summary> <div class="details__content"> <ul class="filters no-bullets"> {% assign brand_prefix = 'brand-' %} {% for tag in collection.all_tags %} {% if tag contains brand_prefix %} {% assign size_readable = tag | remove: brand_prefix | replace: '-', ' ' | upcase %} {% if current_tags contains tag %} {% assign display_url = size_readable | link_to_remove_tag: tag %} <li class="filter--active filters-clear"> <span class="icon icon-cross icon--small"></span> {{ display_url }} </li> {% else %} {% assign display_url = size_readable | link_to_add_tag: tag %} <li> {{ display_url }} </li> {% endif %} {% endif %} {% endfor %} </ul> </div> </details>

Comments

There are no comments yet.

You need to be logged in to post comments.



Welcome to Snippet Repo!

Discover, share and save useful code snippets.

Join our community over over 2,000 members! Currently a 48% acceptance rate. Apply for membership →