How to filter top 10 best-sellers on Stiletto theme collection page?

Hi,

I’ve created a collection page for ‘best-sellers’.

The problem I’m facing is that I’m unable to filter by best-selling and limit to the top 10 products. It’s pulling through all products in my store. :disappointed_face:

Does anyone know a workaround for this?

I’m using the Stiletto theme.

Thanks

Aneby

Hi Aneby,

I don’t have a Stiletto Theme, but I am sure most themes are similar, so follow these steps:

  1. find file name main-collection.liquid OR collection.liquid

  2. Find a line of code similar to this {%- for product in collection.products -%}

  3. and replace it with following:

{% if collection.handle == 'best-sellers' and forloop.index == 11 %}
{% break %}
{% endif %}

Hi Kevin,

Thank you for the suggested solution.

I’ve managed to locate main-collection-product-grid.liquid and found the below code:

{% for product in collection.products %}
{%

However, when I added your code the red squiggly lines appeared?

Do you mind sharing a Screenshot of the code or a paste the code file?

Hey Kevin,

Please see below

Cheers

Ryan

{%- liquid
  assign per_page = section.settings.rows | times: section.settings.columns
  assign paginated = false
  if section.settings.display_type == 'all'
    assign paginated = true
  endif
-%}
{%- capture image_sizes -%}
  (min-width: 720px) calc(calc(100vw - calc(2 * clamp(18px, 3.3vw, 3.3vw))) / {{ section.settings.columns }}),
  calc(calc(100vw - calc(2 * clamp(18px, 3.3vw, 3.3vw))) / {{ section.settings.mobile_columns }})
{%- endcapture -%}

{% paginate collections by per_page %}
  
    

      

      
        {%- if section.settings.display_type == 'all' -%}
          {%- for collection in collections -%}
            {%
              render 'collection-item' with
              collection: collection,
              aspect_ratio: section.settings.collection_listing_aspect_ratio,
              label_style: section.settings.label_style,
              overlay_text_color: section.settings.overlay_text_color,
              overlay_title_background: section.settings.overlay_title_background,
              overlay_title_background_style: section.settings.overlay_title_background_style
              image_sizes: image_sizes
            %}
          {%- endfor -%}
        {%- else -%}
          {%- for collection_item in section.settings.collection_list -%}
            {%
              render 'collection-item' with
              collection: collection_item,
              aspect_ratio: section.settings.collection_listing_aspect_ratio,
              label_style: section.settings.label_style,
              overlay_text_color: section.settings.overlay_text_color,
              overlay_title_background: section.settings.overlay_title_background,
              overlay_title_background_style: section.settings.overlay_title_background_style,
              image_sizes: image_sizes
            %}
          {%- else -%}
            {%- for i in (1..per_page) -%}
              {%
                render 'collection-item' with
                collection: collection,
                aspect_ratio: section.settings.collection_listing_aspect_ratio,
                label_style: section.settings.label_style,
                overlay_text_color: section.settings.overlay_text_color,
                overlay_title_background: section.settings.overlay_title_background,
                overlay_title_background_style: section.settings.overlay_title_background_style
                image_sizes: image_sizes,
              %}
            {%- endfor -%}
          {%- endfor -%}
        {%- endif -%}
      

      {% if paginated %}
        
          {% if paginate.pages > 1 %}
            {%
              render 'pagination' with
              paginate: paginate,
              type: 'general.pagination.collections',
              show_item_count: true
            %}
          {% else %}
            {%
              render 'pagination' with
              paginate: paginate,
              type: 'general.pagination.collections',
              display_paginate_item_count_only: true
            %}
          {% endif %}
        

      {% endif %}
    

  

{% endpaginate %}

{% schema %}
{
  "name": "t:sections.main_list_collections.name",
  "tag": "section",
  "settings": [
    {
      "type": "paragraph",
      "content": "t:sections.main_list_collections.settings.paragraph.content"
    },
    {
      "id": "display_type",
      "type": "radio",
      "label": "t:sections.main_list_collections.settings.display_type.label",
      "default": "all",
      "options": [
        {
          "value": "all",
          "label": "t:sections.main_list_collections.settings.display_type.options__1"
        },
        {
          "value": "selected",
          "label": "t:sections.main_list_collections.settings.display_type.options__2"
        }
      ]
    },
    {
      "id": "collection_list",
      "type": "collection_list",
      "label": "t:sections.collection_sections_shared.settings.collection_list.label"
    },
    {
      "type": "select",
      "id": "columns",
      "label": "t:sections.collection_sections_shared.settings.collection_columns.label",
      "default": "3",
      "options": [
        {
          "value": "3",
          "label": "t:sections.collection_sections_shared.settings.columns.option_3"
        },
        {
          "value": "4",
          "label": "t:sections.collection_sections_shared.settings.columns.option_4"
        },
        {
          "value": "5",
          "label": "t:sections.collection_sections_shared.settings.columns.option_5"
        }
      ]
    },
    {
      "type": "select",
      "id": "mobile_columns",
      "label": "t:sections.collection_sections_shared.settings.mobile_collection_columns.label",
      "default": "2",
      "options": [
        {
          "value": "1",
          "label": "t:sections.collection_sections_shared.settings.mobile_columns.option_1"
        },
        {
          "value": "2",
          "label": "t:sections.collection_sections_shared.settings.mobile_columns.option_2"
        }
      ]
    },
    {
      "type": "select",
      "id": "rows",
      "label": "t:sections.collection_sections_shared.settings.rows.label",
      "default": "4",
      "options": [
        {
          "value": "3",
          "label": "t:sections.collection_sections_shared.settings.rows.option_3"
        },
        {
          "value": "4",
          "label": "t:sections.collection_sections_shared.settings.rows.option_4"
        },
        {
          "value": "5",
          "label": "t:sections.collection_sections_shared.settings.rows.option_5"
        },
        {
          "value": "6",
          "label": "t:sections.collection_sections_shared.settings.rows.option_6"
        },
        {
          "value": "7",
          "label": "t:sections.collection_sections_shared.settings.rows.option_7"
        },
        {
          "value": "8",
          "label": "t:sections.collection_sections_shared.settings.rows.option_8"
        },
        {
          "value": "9",
          "label": "t:sections.collection_sections_shared.settings.rows.option_9"
        },
        {
          "value": "10",
          "label": "t:sections.collection_sections_shared.settings.rows.option_10"
        }
      ]
    },
    {
      "type": "header",
      "content": "t:shared.settings.collection_listing.header_collection_listing.content"
    },
    {
      "type": "select",
      "id": "collection_listing_aspect_ratio",
      "label": "t:shared.settings.collection_listing.collection_listing_aspect_ratio.label",
      "default": "square",
      "options": [
        {
          "value": "natural",
          "label": "t:shared.settings.aspect_ratio.option_natural"
        },
        {
          "value": "square",
          "label": "t:shared.settings.aspect_ratio.option_square"
        },
        {
          "value": "portrait",
          "label": "t:shared.settings.aspect_ratio.option_portrait"
        },
        {
          "value": "landscape",
          "label": "t:shared.settings.aspect_ratio.option_landscape"
        }
      ]
    },
    {
      "type": "select",
      "id": "label_style",
      "label": "t:shared.settings.collection_listing.label_style.label",
      "default": "overlay",
      "options": [
        {
          "value": "overlay",
          "label": "t:shared.settings.collection_listing.label_style.option_overlay"
        },
        {
          "value": "beneath",
          "label": "t:shared.settings.collection_listing.label_style.option_beneath"
        }
      ]
    },
    {
      "type": "select",
      "id": "overlay_title_background_style",
      "label": "t:shared.settings.collection_listing.overlay_title_background_style.label",
      "default": "gradient",
      "options": [
        {
          "value": "solid",
          "label": "t:shared.settings.collection_listing.overlay_title_background_style.option_solid"
        },
        {
          "value": "gradient",
          "label": "t:shared.settings.collection_listing.overlay_title_background_style.option_gradient"
        }
      ]
    },
    {
      "type": "color",
      "id": "overlay_text_color",
      "label": "t:shared.settings.collection_listing.overlay_text_color.label",
      "default": "#fff"
    },
    {
      "type": "color",
      "id": "overlay_title_background",
      "label": "t:shared.settings.collection_listing.overlay_title_background.label",
      "default": "#000000"
    },
    {
      "type": "header",
      "content": "t:shared.settings.section_style.header_style.content"
    },
    {
      "id": "enable_animation",
      "type": "checkbox",
      "label": "t:shared.settings.section_style.enable_animation.label",
      "info": "t:shared.settings.section_style.enable_animation.info",
      "default": true
    }
  ]
}
{% endschema %}

it seems like item are render in this file: collection-item.liquid

This is the code from collection-item.liquid :slightly_smiling_face:

{%- comment -%}
  Pass these variables into snippet:

  Required:

  * collection: Collection object
  * label_style: String
  * overlay_title_background: Color_picker value
  * overlay_title_background_style: String
  * image_sizes: String (passed to image as sizes attribute)

  Optional:

  * aspect_ratio: String
  * placeholder: Bool - show placeholder content if passed
{%- endcomment -%}

{%- liquid
  assign label_is_overlay = false

  if label_style == 'overlay'
    assign label_is_overlay = true
  endif
-%}
{% capture collection_label %}
  
    #### 
      {%- if label_is_overlay -%}
        
          {%- if placeholder -%}
            {{ 'collections.general.collection_label' | t }}
          {%- else -%}
            {{ collection.title }}
          {%- endif -%}
        
        
          {%- render 'icon' with icon: 'arrow-short' -%}
        
      {%- else -%}
        {%- if placeholder -%}
          {{ 'collections.general.collection_label' | t }}
        {%- else -%}
          {{ collection.title }}
        {%- endif -%}
      {%- endif -%}
    
  

{% endcapture %}

  {%- capture wrapping_tag -%}
    {%- if include_placeholder -%}div{%- else -%}a{%- endif -%}
  {%- endcapture -%}
  {%- capture wrapping_attributes -%}
    {%- unless include_placeholder -%}href="{{ collection.url }}" aria-label="{{ collection.title }}"{%- endunless -%}
  {%- endcapture -%}
  <{{ wrapping_tag }}
    {{ wrapping_attributes }}
    class="collection-item__image-wrapper hover"
  >
    {%
      render 'image' with
      image: collection.featured_image,
      wrapper_class: 'collection-item__image',
      aspect_ratio: aspect_ratio,
      placeholder_name: 'collection-1',
      include_placeholder: true,
      sizes: image_sizes,
      src_set_type: "grid"
    %}

    {%- if label_is_overlay -%}
      {{ collection_label }}
    {%- endif -%}
  

  {%- unless label_is_overlay -%}
    {{ collection_label }}
  {%- endunless -%}

you sure above code is from: main-collection-product-grid.liquid

Sorry the code before was from collection-item.liquid

The code for main-collection-product-grid.liquid is here:

{%- liquid
  assign paginated = false
  if section.settings.pagination == 'paginated'
    assign paginated = true
  endif

  assign per_page = section.settings.rows | times: section.settings.columns
  assign filter_bar_enabled = false
  if section.settings.show_item_count or section.settings.show_sort or section.settings.show_filters
    assign filter_bar_enabled = true
  endif
-%}

{% schema %}
{
  "name": "t:sections.main_collection_product_grid.name",
  "class": "collection-section",
  "settings": [
    {
      "type": "header",
      "content": "t:sections.main_collection_product_grid.settings.collection__header.content"
    },
    {
      "type": "select",
      "id": "columns",
      "label": "t:sections.collection_sections_shared.settings.collection_columns.label",
      "default": "4",
      "options": [
        {
          "value": "2",
          "label": "t:sections.collection_sections_shared.settings.columns.option_2"
        },
        {
          "value": "3",
          "label": "t:sections.collection_sections_shared.settings.columns.option_3"
        },
        {
          "value": "4",
          "label": "t:sections.collection_sections_shared.settings.columns.option_4"
        },
        {
          "value": "5",
          "label": "t:sections.collection_sections_shared.settings.columns.option_5"
        }
      ]
    },
    {
      "type": "select",
      "id": "rows",
      "label": "t:sections.collection_sections_shared.settings.rows.label",
      "default": "4",
      "options": [
        {
          "value": "3",
          "label": "t:sections.collection_sections_shared.settings.rows.option_3"
        },
        {
          "value": "4",
          "label": "t:sections.collection_sections_shared.settings.rows.option_4"
        },
        {
          "value": "5",
          "label": "t:sections.collection_sections_shared.settings.rows.option_5"
        },
        {
          "value": "6",
          "label": "t:sections.collection_sections_shared.settings.rows.option_6"
        },
        {
          "value": "7",
          "label": "t:sections.collection_sections_shared.settings.rows.option_7"
        },
        {
          "value": "8",
          "label": "t:sections.collection_sections_shared.settings.rows.option_8"
        },
        {
          "value": "9",
          "label": "t:sections.collection_sections_shared.settings.rows.option_9"
        },
        {
          "value": "10",
          "label": "t:sections.collection_sections_shared.settings.rows.option_10"
        }
      ]
    },
    {
      "type": "checkbox",
      "id": "show_item_count",
      "label": "t:shared.settings.show_item_count.label",
      "default": true
    },
    {
      "type": "header",
      "content": "t:shared.settings.filtering__header.content"
    },
    {
      "id": "show_sort",
      "type": "checkbox",
      "label": "t:shared.settings.show_sort.label",
      "default": true
    },
    {
      "id": "show_filters",
      "type": "checkbox",
      "label": "t:shared.settings.show_filters.label",
      "info": "t:shared.settings.show_filters.info",
      "default": true
    },
    {
      "type": "checkbox",
      "id": "enable_sticky_filter_bar",
      "label": "t:shared.settings.enable_sticky_filter_bar.label",
      "default": true
    },
    {
      "type": "checkbox",
      "id": "collapse_filter_bar",
      "label": "t:shared.settings.collapse_filter_bar.label",
      "default": true
    },
    {
      "type": "checkbox",
      "id": "collapse_filter_groups_mobile",
      "label": "t:shared.settings.collapse_filter_groups_mobile.label",
      "default": true
    },
    {
      "id": "show_swatch_filters",
      "type": "checkbox",
      "label": "t:shared.settings.show_swatch_filters.label",
      "info": "t:shared.settings.show_swatch_filters.info",
      "default": true
    },
    {
      "id": "show_chip_filters",
      "type": "checkbox",
      "label": "t:shared.settings.show_chip_filters.label",
      "info": "t:shared.settings.show_chip_filters.info",
      "default": true
    },
    {
      "type": "select",
      "id": "chip_layout",
      "label": "t:shared.settings.chip_layout.label",
      "default": "3col",
      "options": [
        {
          "value": "3col",
          "label": "t:shared.settings.chip_layout.option_3col"
        },
        {
          "value": "2col",
          "label": "t:shared.settings.chip_layout.option_2col"
        },
        {
          "value": "natural",
          "label": "t:shared.settings.chip_layout.option_natural"
        }
      ]
    },
    {
      "type": "header",
      "content": "t:shared.settings.pagination__header.content"
    },
    {
      "type": "select",
      "id": "pagination",
      "label": "t:shared.settings.pagination.label",
      "default": "paginated",
      "options": [
        {
          "value": "infinite",
          "label": "t:shared.settings.pagination.options__1"
        },
        {
          "value": "click",
          "label": "t:shared.settings.pagination.options__2"
        },
        {
          "value": "paginated",
          "label": "t:shared.settings.pagination.options__3"
        }
      ],
      "info": "t:sections.main_collection_product_grid.settings.pagination.info"
    },
    {
      "type": "header",
      "content": "t:sections.main_collection_product_grid.settings.style__header.content"
    },
    {
      "id": "enable_animation",
      "type": "checkbox",
      "label": "t:shared.settings.section_style.enable_animation.label",
      "info": "t:shared.settings.section_style.enable_animation.info",
      "default": true
    },
    {
      "type": "select",
      "id": "divider_style",
      "label": "t:shared.settings.section_style.divider_style.label",
      "default": "none",
      "options": [
        {
          "label": "t:shared.settings.section_style.divider_style.option_none",
          "value": "none"
        },
        {
          "label": "t:shared.settings.section_style.divider_style.option_solid",
          "value": "solid"
        }
      ]
    }
  ]
}
{% endschema %}