Shopify Categories Within Collections

How to use Liquid to create product navigation in Shopify

collection-categoriesShopify doesn’t have categories so to speak, but it does have collections and tag and you can combine them to make powerful and intuitive product navigation.

<ul class="collections"> {% for collection in collections %}
{% if collection.handle != 'frontpage' %}
<li><h3><a href="{{ collection.url }}" title="{{ collection.title }}">{{ collection.title }}</a></h3>
<ul class="tags"> {% for tag in collection.all_tags %}
<li><a href="{{ collection.url }}/{{ tag | handleize }}" title="{{ tag | escape }}">{{ tag }}</a></li>
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
</ul>

The above code will create a product navigation of all your collections and all the tags within the appropriate collection. The third line of code is use to exclude collection such as the frontpage collection which isn’t really appropriate in your product navigation.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>