How can I limit the number of products in my Best Selling collection?

Hello Team

I wanna create a new collection of all products “Best Selling”, then I create a new collection, add all products in here, press to list by best selling, but how I can make that collection which shows all products on a webpage just show 10 or 20 products, not all products. I have found in internet need add some code, but I am not sure. In some of the post I see they can choose products limit, but in my theme, I don’t find it.

Maybe can help me?

I add some pictures:

Like here I can’t find in my theme section.

How to create that limit of products?

Theme: Impulse

Web: dehome.co.uk

Thanks.

Hi @Deoxes ,

Please change it to 10 or 20, it will work fine

1 Like

@LitCommerce

Yes but I send this photo found from the internet, not from mine, at my theme I can’t find that section.

Thanks.

@LitCommerce If I don’t have that product limit section, maybe it helps some code?

Hi @Deoxes ,

Please send me the code of main-collection.liquid file, I will check and add it for you

1 Like

@LitCommerce

I now didn’t create the best-selling collection, just don’t know how to do it with all products and they can show just 10 or 15 in the collection.

I will send you my code, and please in which section do I need to make changes when I create that collection?

Add some code maybe or what?

{% render 'collection-sidebar', section: section %}
{% render 'collection-template', section: section %}

{% schema %}
{
“name”: “Product grid”,
“settings”: [
{
“type”: “header”,
“content”: “Filtering and sorting”
},
{
“type”: “checkbox”,
“id”: “enable_sidebar”,
“label”: “Enable filter”,
“default”: true,
“info”: “Allow your customers to filter collections and search results by product availability, price, color, and more. Customize filters
},
{
“type”: “checkbox”,
“id”: “collapsed”,
“label”: “Collapse filters”,
“default”: true
},
{
“type”: “select”,
“id”: “filter_style”,
“label”: “Filter style”,
“default”: “sidebar”,
“options”: [
{
“value”: “sidebar”,
“label”: “Sidebar”
},
{
“value”: “drawer”,
“label”: “Drawer”
}
]
},
{
“type”: “checkbox”,
“id”: “enable_color_swatches”,
“label”: “Enable color swatches”,
“info”: “View setup instructions
},
{
“type”: “checkbox”,
“id”: “enable_sort”,
“label”: “Show sort options”,
“default”: true
}
],
“blocks”: [
{
“type”: “collection_description”,
“name”: “Collection description”,
“limit”: 1
},
{
“type”: “product_grid”,
“name”: “Products”,
“settings”: [
{
“type”: “checkbox”,
“id”: “enable_collection_count”,
“label”: “Enable collection count”,
“default”: true
},
{
“type”: “range”,
“id”: “per_row”,
“label”: “Products per row”,
“default”: 4,
“min”: 2,
“max”: 5,
“step”: 1
},
{
“type”: “range”,
“id”: “rows_per_page”,
“label”: “Rows per page”,
“default”: 7,
“min”: 3,
“max”: 20,
“step”: 1
},
{
“type”: “checkbox”,
“id”: “mobile_flush_grid”,
“label”: “Flush grid on mobile”,
“default”: false
}
],
“limit”: 1
},
{
“type”: “subcollections”,
“name”: “Subcollections”,
“settings”: [
{
“type”: “paragraph”,
“content”: “Links to collections from your menu will appear here. Learn more
},
{
“type”: “range”,
“id”: “subcollections_per_row”,
“label”: “Subcollections per row”,
“default”: 5,
“min”: 2,
“max”: 5,
“step”: 1
}
],
“limit”: 1
}
]

}
{% endschema %}

@LitCommerce

But when I will create that collection, I wanna just in that collection will show 15 or 20 products, not in all collections.

Hi @Deoxes ,

Please send me more code of collection-template.liquid file, I will help you add options for it.

Or you can create me a staff account, I’ll help you add it quickly.

1 Like

@LitCommerce

Hi mate, can you write me where each code needs to add, I wanna add it myself to know if I need to take it out, take it myself don’t ask someone to help If you can do that ofcourse.

Thanks.

Hi @Deoxes ,

Please add code with following condition, it will work fine.

Code:

{%- if collection.handle == 'handle collection 1' or collection.handle == 'handle collection 2' -%}
  {%- assign paginate_by = 10 -%}
{%- endif -%}

Then you find ‘collection.products’ and change code:

Code:

{%- if collection.handle == 'handle collection 1' or collection.handle == 'handle collection 2' -%}
      {%- for product in collection.products limit: 10 -%}
        {%- include 'product-grid-item' -%}
      {%- else -%}
        
          

{{ 'collections.general.no_matches' | t }}

        

      {%- endfor -%}
    {%- else -%}
      {%- for product in collection.products -%}
        {%- include 'product-grid-item' -%}
      {%- else -%}
        
          

{{ 'collections.general.no_matches' | t }}

        

      {%- endfor -%}
    {%- endif -%}

Hope it helps!

1 Like

@LitCommerce

But in which file I need add it? Because look my looks different:

And can you show me in which place I can choose which I want to do the collection?

Because I don’t need at all of them, just in one.

Many Thanks.

Hi @Deoxes ,

Please send me the code of the whole file, I will help you to add it.

1 Like

@LitCommerce

Which file do I need to send you?

main-collection.liquid?

or collection-template.liquid,

Because main-collection.liquid I had added for you in older messages.

Thanks.

Hi @Deoxes ,

Please send collection-template.liquid file.

1 Like

@LitCommerce

Just please show me where I need to make changes and where I need to choose the collection which I wanna set limits because how I told you before, I don’t wanna set limits on all collections.

Thanks.

File:

{%- liquid
assign per_row = 4
assign paginate_by = per_row | times: 7

for block in section.blocks
case block.type
when ‘product_grid’
assign per_row = block.settings.per_row
assign paginate_by = per_row | times: block.settings.rows_per_page
endcase
endfor

assign current_filter_size = 0

for filter in collection.filters
assign current_filter_size = current_filter_size | plus: filter.active_values.size
endfor
-%}

{%- paginate collection.products by paginate_by -%}

{%- for block in section.blocks -%}

{%- case block.type -%} {%- when 'collection_description' -%} {%- if collection.description != blank and current_filter_size == 0 -%}
{{ collection.description }}
{%- endif -%} {%- when 'subcollections' -%} {%- if current_filter_size == 0 -%} {%- render 'subcollections', per_row: block.settings.subcollections_per_row -%} {%- endif -%} {%- when 'product_grid' -%}
{%- liquid assign current_filter_size = 0

for filter in collection.filters
assign current_filter_size = current_filter_size | plus: filter.active_values.size
endfor
-%}

{{ 'collections.filters.title_tags' | t }} {%- if current_filter_size > 0 -%} ({{ current_filter_size }}) {%- endif -%}
{%- if block.settings.enable_collection_count -%} {{ 'collections.general.items_with_count' | t: count: collection.products_count }} {%- endif -%}
{%- assign sort_by = collection.sort_by | default: collection.default_sort_by -%} {{ 'collections.sorting.title' | t }}

{%- if block.settings.enable_collection_count -%}

{{ 'collections.general.items_with_count' | t: count: collection.products_count }}

{%- endif -%}
{%- liquid assign grid_item_width = 'small--one-half medium-up--one-third'

case per_row
when 2
assign grid_item_width = ‘medium-up–one-half’
when 3
assign grid_item_width = ‘small–one-half medium-up–one-third’
when 4
assign grid_item_width = ‘small–one-half medium-up–one-quarter’
when 5
assign grid_item_width = ‘small–one-half medium-up–one-fifth’
endcase
-%}

{%- for product in collection.products -%}
{%- render ‘product-grid-item’,
product: product,
grid_item_width: grid_item_width,
per_row: per_row -%}
{%- else -%}

{{ 'collections.general.no_matches' | t }}

{%- endfor -%}

{%- if paginate.pages > 1 -%}
{%- render ‘pagination’, paginate: paginate -%}
{%- endif -%}

{%- if settings.quick_shop_enable -%}
{%- for product in collection.products -%}
{%- render ‘quick-shop-modal’, product: product -%}
{%- endfor -%}
{%- endif -%}
{%- endcase -%}

{%- endfor -%}

{%- endpaginate -%}

Hi @Deoxes ,

Please change all code:

{%- liquid
assign per_row = 4
assign paginate_by = per_row | times: 7

for block in section.blocks
case block.type
when 'product_grid'
assign per_row = block.settings.per_row
assign paginate_by = per_row | times: block.settings.rows_per_page
endcase
endfor

assign current_filter_size = 0

for filter in collection.filters
assign current_filter_size = current_filter_size | plus: filter.active_values.size
endfor
-%}

{%- if collection.handle == 'handle collection 1' or collection.handle == 'handle collection 2' -%}
  {%- assign paginate_by = 10 -%}
{%- endif -%}

{%- paginate collection.products by paginate_by -%}

{%- for block in section.blocks -%}

  {%- case block.type -%}
  {%- when 'collection_description' -%}
  {%- if collection.description != blank and current_filter_size == 0 -%}
  

    {{ collection.description }}
  

  {%- endif -%}
  {%- when 'subcollections' -%}
  {%- if current_filter_size == 0 -%}
  {%- render 'subcollections', per_row: block.settings.subcollections_per_row -%}
  {%- endif -%}
  {%- when 'product_grid' -%}
  
    {%- liquid
assign current_filter_size = 0

for filter in collection.filters
assign current_filter_size = current_filter_size | plus: filter.active_values.size
endfor
-%}
    

      
    

    
      {%- if block.settings.enable_collection_count -%}
      {{ 'collections.general.items_with_count' | t: count: collection.products_count }}
      {%- endif -%}
    

    
      

        {%- assign sort_by = collection.sort_by | default: collection.default_sort_by -%}
        
        
      

    

  

  {%- if block.settings.enable_collection_count -%}
  

{{ 'collections.general.items_with_count' | t: count: collection.products_count }}

  {%- endif -%}

  
    {%- liquid
assign grid_item_width = 'small--one-half medium-up--one-third'

case per_row
when 2
assign grid_item_width = 'medium-up--one-half'
when 3
assign grid_item_width = 'small--one-half medium-up--one-third'
when 4
assign grid_item_width = 'small--one-half medium-up--one-quarter'
when 5
assign grid_item_width = 'small--one-half medium-up--one-fifth'
endcase
-%}
	{%- if collection.handle == 'handle collection 1' or collection.handle == 'handle collection 2' -%}
      {%- for product in collection.products limit: 10 -%}
        {%- render 'product-grid-item',
        product: product,
        grid_item_width: grid_item_width,
        per_row: per_row -%}
      {%- else -%}
        

          

{{ 'collections.general.no_matches' | t }}

        

      {%- endfor -%}
    {%- else -%}
      {%- for product in collection.products -%}
        {%- render 'product-grid-item',
        product: product,
        grid_item_width: grid_item_width,
        per_row: per_row -%}
      {%- else -%}
        
          

{{ 'collections.general.no_matches' | t }}

        

      {%- endfor -%}
    {%- endif -%}

  

  {%- if paginate.pages > 1 -%}
  {%- render 'pagination', paginate: paginate -%}
  {%- endif -%}

  {%- if settings.quick_shop_enable -%}
  {%- for product in collection.products -%}
  {%- render 'quick-shop-modal', product: product -%}
  {%- endfor -%}
  {%- endif -%}
  {%- endcase -%}

{%- endfor -%}

{%- endpaginate -%}

Then you just need to change ‘handle collection 1’ to the handle of the collection, it will display fine

1 Like

@LitCommerce

I had changed the code now in which collection I wanna shows just 10 product I need set the collection name here?

Thanks.

@LitCommerce

Changed but nothing.

@LitCommerce

Not working mate.

Hi @Deoxes ,

You can send me the link of the collection you want to change, I will guide you in detail with the code

1 Like