FROM CACHE - en_header

Simple Theme - Hide Empty Collections

Solved
gchaney
Excursionist
37 2 4

Website: Juststuffisell.com

 

Using the simple theme. 

 

Working on finishing up the configuration for the new site and need some assistance with a few things. First one is I need to be able to hide empty collections and sub-collections automatically and to have them repopulate as items are added to them. 

 

I've tried a couple of processes for other themes that did not work in this one and was not able to find one that was done for the simple theme.

 

Any help would be greatly appreciated 🙂

 

Accepted Solution (1)

Accepted Solutions
Lixon_Louis
Shopify Partner
1193 35 271

This is an accepted solution.

You can hide the empty collections using the condition below.

 

{% if collection.products_count != 0 %}
...
{% endif%}

Take  https://juststuffisell.com/collections  as an example . The code is in sections/list-collections-template.liquid in Simple theme. I have added this condition inside the loop before the grid__item . You can use the same logic if you are using blocks too.

screenshot-nichegeek.myshopify.com-2020.01.png

 

 

 

 

 

 

View solution in original post

Replies 10 (10)
gchaney
Excursionist
37 2 4
Lixon_Louis
Shopify Partner
1193 35 271

This is an accepted solution.

You can hide the empty collections using the condition below.

 

{% if collection.products_count != 0 %}
...
{% endif%}

Take  https://juststuffisell.com/collections  as an example . The code is in sections/list-collections-template.liquid in Simple theme. I have added this condition inside the loop before the grid__item . You can use the same logic if you are using blocks too.

screenshot-nichegeek.myshopify.com-2020.01.png

 

 

 

 

 

 

gchaney
Excursionist
37 2 4

Thank a million!!!!

shopany
Excursionist
16 0 0

Hi Lixon_Louis

 

I was so happy to find your solution here and I tried immediately, but unfortunately it doesn't work on my side. I have the Theme DEBUT (VERSION 11.0.1) installed. Could that be the reason? My code looks a little bit different, but not so much…

 

{% for collection in collections %}
    <li class="grid__item {{ grid_item_width }}">
        {% include 'collection-grid-item', collection_image_size: image_size %}
    </li>
{% endfor %}

this code I changed to…

{% for collection in collections %}
    {% if collection.products_count != 0 %}
        <li class="grid__item {{ grid_item_width }}">
            {% include 'collection-grid-item', collection_image_size: image_size %}
        </li>
    {% endif %}
{% endfor %}

I would be very grateful if you could take a look at it. Thank you in advance

Stefanos

shopany – shop anytime
Lixon_Louis
Shopify Partner
1193 35 271

The solution is same for Debut. I suppose your collections are not empty then. Or are you talking about inventory_quantity? @shopany 

shopany
Excursionist
16 0 0

Hi @Lixon_Louis

 

Thank you for your fast reply.

The collections are empty. I have a lot of empty collection right now, because I have not finished assigning the products. There is inventory available, but it's not linked / allocated to the collection.

shopany – shop anytime
ntcrawler
Tourist
5 0 2

I may have missed something in this process. I edited my theme, went to the file that was listed in the example, and added the code:

{% if collection.products_count != 0 %}


Where it was suggested to add the code. I saved the file, refreshed and when i previewed my site, the empty menu items (collections) were still visible.
Is there something I am missing here? Please advise,




list-collections-template.liquidlist-collections-template.liquidLive SiteLive Site

partpartpart
Excursionist
20 0 6

Hi @Lixon_Louis I have the same issue.

I follow the code that you gave but still the empty collection is visible on sidebar.

Hope you can help us too.

Thank you!

JusticeJackie07
New Member
1 0 0

Below is How to Hide Empty Collections and display only collections that has more than one data count
<li> {% for collection in collections %}
{% if collection.products_count != 0 %}
<br><a href="{{ collection.url }}"> {{ collection.title }} <span class="count">({{collection.products_count}})</span></a>
{% endif%} {% endfor %} </li>

PB79
Pathfinder
108 2 37

Hello @Lixon_Louis 

I would really appreciate it if you could help me with this issue on my custom porto theme 🙂