shopify

Retrieve all Shopify collections matching specific tag


I'm trying to retrieve all Shopify collections for our store which have products matching tag dog.

{% for collection in collections %}
  {% assign gato = 'false' %}
  {% assign perro = 'false' %}

  {% for tag in collection.tags %}
    {% if tag == 'Cat' %}
        {% assign cat = 'true' %}
    {% elsif tag == 'Dog' %}
        {% assign dog = 'true' %}
    {% endif %}    
  {% endfor %}

  {% if dog == 'true' and cat == 'false' %}
      <li>{{ collection.title | link_to: collection.url }}</li>
  {% endif %}

{% endfor %}

I successfully get this list when I'm at homepage (telepienso.com). (See footer screenshot: A). I have the same exact code in collection.liquid and I get some of the collections but NOT all of them. (telepienso.com/collections/all). (See list on the right screenshot: B). Is there any restriction inside collection.liquid which can affect?

A screenshot (productos para perros list):

footer-screenshot


B screenshot (sección perros list):

list-screenshot


Solution

  • This was the cause of the problem. The collections variable was being paginated.

    By moving the code in the question outside of the paginate liquid tag, all collections are displayed in the sidebar (the same as the footer).


    EDIT: The above link is broken because the question was deleted due to low traffic. I've copied the content from the question below for reference.

    Shopify - issue accessing the collections global variable inside paginate

    I would like to be able to access the collections global variable from within a paginated group of products, but the collections variable is also paginated if it is accessed within a paginate liquid tag.

    For example (in collection.liquid):

    {% for collection in collections %}
      {{ collection.title }}
    {% endfor %}
    <br />
    
    {% paginate collection.products by 4 %}
      {% for collection in collections %}
        {{ collection.title }}
      {% endfor %}
      ...
    {% endpaginate %}
    

    Output:

    All Collection1 Collection2 Collection3 Collection4 Collection5 Collection6 Frontpage
    All Collection1 Collection2 Collection3

    The for loop before the paginate tag lists all collections as you would expect, but doing the same thing within the paginate tag causes collections to be paginated as well as the products I am actually wanting to paginate.

    Is there a way to access the collections global variable within a paginated group of products without it also being affected by the pagination?

    Why would I want to do this? It was causing this problem, and was not immediately obvious because the code using the collections variable was in a separate snippet to the code with the pagination.


    EDIT 2: I can no longer reproduce this issue, it appears to have been fixed.