How to retrieve a list of categories and n childs on the front end? (only categories with products)

10 0 2



I need to build a mega menu in the front end and would like to know if there's a way to retireve the category tree (only categories with products in it).


Also, is there a way to create custom category tree?

Replies 2 (2)

Shopify Partner
1242 197 206

@rafaelmarques you can fetched the collection into megamenu by adding follow code : 

      {%- for link in linklists.categories.links -%}
          <li class="collection-list__item grid__item">
            {% render 'card-collection', card_collection: link.object, media_aspect_ratio: section.settings.image_ratio, columns: 3 %}
      {%- endfor -%}
10 0 2

Hi @Ujjaval , thanks for replying. I might have left out some info in my question. I'm not using the LIQUID template, I'm working on a custom store front that integrates everything via graphql api. So I'd need to get the category tree from there. Do you know if it's possible?