Exclude products by tag from homepage featured collection

Solved
Tourist
5 0 0

Hello, I have tagged all products without an image as "No Image", so I now want to exclude these products from my homepage featured collection. They should still be visible in every other page (Collection, search, related products pages etc) except on the homepage. How can I achieve this? Thanks

0 Likes
Astronaut
1082 147 272

You can't exclude products from a collection based on what their tags contain, only include them, though it is a much requested feature. I would love for that to be the case. You can keep them from showing up though in your featured collection code. Inside the for loop that outputs your products, you can use an unless statement to not render them:

 

//for loop would look something like this:

{% for product in collections.featured-collection.products %}
{% unless product.tags contains "no-image" %}

//code to output your product. Sometimes this is collection-template.liquid, but it could be anything.

{% endunless %}
{% endfor %}
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
Tourist
5 0 0

Thanks @Ninthony. Please where exactly am I supposed to add this code? Below is my featured-collection.liquid code

{%- capture section_settings -%}
{
  "stackable": {% if section.settings.layout == 'vertical' and section.settings.stack_desktop == false %}false{% else %}true{% endif %},
  "layout": {{ section.settings.layout | json }}
}
{%- endcapture -%}

<section class="section" data-section-id="{{ section.id }}" data-section-type="featured-collection" data-section-settings='{{ section_settings }}'>
 
  {%- assign collection = collections[section.settings.collection] -%}

  <div class="container">
    <header class="section__header">
      <div class="section__header-stack">
        <h2 class="section__title heading h3">{{ section.settings.title | default: collection.title | escape }}</h2>
      </div>

      {%- if section.settings.link_title != blank -%}
        <a href="{{ section.settings.link_url | default: collection.url | default: '#' }}" class="section__action-link link">{{ section.settings.link_title | escape }} {% include 'icon' with 'tail-right' %}</a>
      {%- endif -%}
    </header>
  </div>

  <div class="container {% if section.settings.layout != 'vertical' %}container--flush{% endif %}">
    {%- capture product_list -%}
      <div class="product-list product-list--{{ section.settings.layout }} {% if section.settings.layout == 'vertical' %}product-list--scrollable{% endif %} {% if section.settings.stack_desktop %}product-list--stackable{% endif %}">
        {%- if collection.empty? -%}
          {%- assign products = (1..section.settings.products_count) -%}
          {%- assign snippet_name = 'product-item-placeholder' -%}
        {%- else -%}
          {%- assign products = collection.products -%}
          {%- assign snippet_name = 'product-item' -%}
        {%- endif -%}

        {%- for product in products limit: section.settings.products_count -%}
          {%- if section.settings.layout == 'vertical' -%}
            {%- include snippet_name, product: product, grid_classes: '1/4--lap 1/5--desk 1/6--wide', show_add_to_cart: section.settings.show_quick_buy -%}
          {%- elsif section.settings.layout == 'horizontal' -%}
            {%- include snippet_name, product: product, horizontal: true, grid_classes: '1/2--tablet 1/3--lap-and-up', show_add_to_cart: false -%}
          {%- else -%}
            {%- assign mod = forloop.index0 | modulo: 3 -%}

            {%- if mod == 0 -%}
              <div class="product-list__column product-list__column--highlight">
            {%- elsif mod == 1 -%}
              <div class="product-list__column {% if forloop.last %}product-list__column--shrink{% endif %}">
            {%- endif -%}

            {%- if mod == 0 -%}
              {%- include snippet_name, product: product, show_add_to_cart: false -%}
            {%- else -%}
              {%- include snippet_name, product: product, horizontal: true, show_add_to_cart: false -%}
            {%- endif -%}

            {%- if mod == 0 or mod == 2 or forloop.last -%}
              </div>
            {%- endif -%}
          {%- endif -%}
        {%- endfor -%}
      </div>
    {%- endcapture -%}

    {%- if section.settings.layout == 'vertical' -%}
      <div class="scroller">
        <div class="scroller__inner">
          {{ product_list }}
        </div>
      </div>
    {%- else -%}
      {{ product_list }}
    {%- endif -%}
  </div>

  {%- comment -%}
  --------------------------------------------------------------------------------------
  QUICK VIEW CONTAINER
  --------------------------------------------------------------------------------------
  {%- endcomment -%}

  <div id="modal-quick-view-{{ section.id }}" class="modal" aria-hidden="true">
    <div class="modal__dialog modal__dialog--stretch" role="dialog">
      <button class="modal__close link" data-action="close-modal">{%- include 'icon' with 'close' -%}</button>

      <div class="modal__loader">
        {%- include 'icon' with 'search-loader' -%}
      </div>

      <div class="modal__inner"></div>
    </div>
  </div>
     
</section>

0 Likes

Success.

Astronaut
1082 147 272

Be sure to backup your theme first, then try here:

 

        {%- for product in products limit: section.settings.products_count -%}
//start your unless statement
{% unless product.tags contains 'no image' %}
          {%- if section.settings.layout == 'vertical' -%}
            {%- include snippet_name, product: product, grid_classes: '1/4--lap 1/5--desk 1/6--wide', show_add_to_cart: section.settings.show_quick_buy -%}
          {%- elsif section.settings.layout == 'horizontal' -%}
            {%- include snippet_name, product: product, horizontal: true, grid_classes: '1/2--tablet 1/3--lap-and-up', show_add_to_cart: false -%}
          {%- else -%}
            {%- assign mod = forloop.index0 | modulo: 3 -%}

            {%- if mod == 0 -%}
              <div class="product-list__column product-list__column--highlight">
            {%- elsif mod == 1 -%}
              <div class="product-list__column {% if forloop.last %}product-list__column--shrink{% endif %}">
            {%- endif -%}

            {%- if mod == 0 -%}
              {%- include snippet_name, product: product, show_add_to_cart: false -%}
            {%- else -%}
              {%- include snippet_name, product: product, horizontal: true, show_add_to_cart: false -%}
            {%- endif -%}

            {%- if mod == 0 or mod == 2 or forloop.last -%}
              </div>
            {%- endif -%}
          {%- endif -%}
//end your unless statement
{% endunless %}
        {%- endfor -%}

Make sure whatever is in quotes after contains is exactly how you tagged your products. It's case sensitive. Also don't include my comments "//start your unless statement" or "//end your unless statement"

If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
1 Like
Tourist
5 0 0

Thank you so much @Ninthony , it worked perfectly. Cheers!!!!

0 Likes
Astronaut
1082 147 272

Glad it helped. If you have another question on something feel free to message me on here. You'll have to enable messaging in your profile.

If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
Tourist
5 0 0

I will have that in mind, thanks :(

0 Likes