Quantcast
Viewing all articles
Browse latest Browse all 12

How to list links to all collections in Shopify (and how to leave out certain collections from that list)

When building a Shopify website (which usually means you’re building or customizing a Shopify theme) it is pretty common to find yourself needing to make a list of all the collections in your store. This might be for a menu or it could be for some other use. Anyway, here is some code that will display an unordered list of links to each collection in your store:

<ul>
  {% for collection in collections %}
    <li><a href="{{ collection.url }}">{{ collection.title }}</a></li>
  {% endfor %}
</ul>

But what if you wanted to leave off one of the collections? It might seem you’d never need to do this, but I’ve seen situations where one collection was featured somewhere else, or where a particular collection had a special landing page that made it necessary to exclude one or more collections from the main list of collections.

So let’s say you had a collection called “shirts” that you did not want to include in your menu of collections. The following code would display the menu minus the “shirts” collection:

<ul>
  {% for collection in collections %}
    {% unless collection.handle == 'shirts' %}
      <li><a href="{{ collection.url }}">{{ collection.title }}</a></li>
    {% endunless %}
  {% endfor %}
</ul>


Viewing all articles
Browse latest Browse all 12

Trending Articles