Created
April 22, 2017 09:40
-
-
Save joe-dempsey/44059697f2b659caf3cd3a15aaa67f47 to your computer and use it in GitHub Desktop.
Tag filter via theme options Shopify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% comment %}Tag filters{% endcomment %} | |
| {% comment %}https://help.shopify.com/themes/customization/collections/filtering-a-collection-with-multiple-tag-drop-down{% endcomment %} | |
| {% comment %}Modified so they can be captured in theme options.{% endcomment %} | |
| {% comment %}first grab and assign some stuff{% endcomment %} | |
| {% capture tags_list %}{{ section.settings.tags_list | prepend: "'," | append: "'" }}{% endcapture %} | |
| {% if collection.url.size == 0 %} | |
| {% assign collection_url = '/collections/all' %} | |
| {% else %} | |
| {% assign collection_url = collection.url %} | |
| {% endif %} | |
| {% assign has_tags = false %} | |
| {% capture tags_html %} | |
| {% comment %}Tag filters{% endcomment %} | |
| {% comment %}replaced default theme code with this: https://help.shopify.com/themes/customization/collections/filtering-a-collection-with-multiple-tag-drop-down{% endcomment %} | |
| {% comment %}Modified so they can be captured in theme options.{% endcomment %} | |
| {% assign tags = tags_list | split: ',' %} | |
| <span class="tags filter"> | |
| <label for="filter-by">{{ 'collections.general.filter_by' | t }}:</label> | |
| <select id="filter-by" class="redirect"> | |
| <option value="{{ collection_url }}">{{ 'collections.general.all_items' | t }}</option> | |
| {% for t in tags %} | |
| {% assign tag = t %} | |
| {% if current_tags contains tag %} | |
| <option value="{{ collection_url }}/{{ tag | handle }}" selected>{{ tag }}</option> | |
| {% elsif collection.all_tags contains tag %} | |
| <option value="{{ collection_url }}/{{ tag | handle }}">{{ tag }}</option> | |
| {% endif %} | |
| {% assign has_tags = true %} | |
| {% endfor %} | |
| </select> | |
| </span> | |
| {% endcapture %} | |
| {% if has_tags %} | |
| {{ tags_html }} | |
| {% endif %} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment