Skip to content

Instantly share code, notes, and snippets.

@cole007
Created June 2, 2015 13:59
Show Gist options
  • Save cole007/ada9bb7a75ba1583d654 to your computer and use it in GitHub Desktop.
Save cole007/ada9bb7a75ba1583d654 to your computer and use it in GitHub Desktop.
Shopify sub-categories hack

This works on the idea of declaring name-spaced collections for sub-cateogries.

For example, creating the following collection

Toys & Games/

We then create the following 'subcategory' collections

Toys & Games/Art & Crafts Toys & Games/Biography Toys & Games/History & Archaeology Toys & Games/Military & Aviation

{% comment %}
For our Collection page liquid template, we'd then use the following to create our navigation:
{% endcomment %}
{% assign current = collection.handle %}
{% if collection.title contains '/' %}
{% assign words = collection.title | split: '/' %}
{% assign section = words[0] | handleize %}
{% for collection in collections %}
{% if collection.handle contains section and collection.title contains '/' %}
<a href="/collections/{{ collection.handle }}">
{% assign words = collection.title | split: '/' %}
{{ words[1] }}
</a><br />
{% endif %}
{% endfor %}
{% else %}
{% if collection.handle %}
{% for collection in collections %}
{% if collection.handle contains current and collection.title contains '/' %}
<a href="/collections/{{ collection.handle }}">
{% assign words = collection.title | split: '/' %}
{{ words[1] }}
</a><br />
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment