Limit Product in a Collection to 20 (Liquid Code Question)

I’ve done some research though couldn’t find a simple explanation of what code snippet to use to limit the products in a collection.

I appreciate that a “forloop” code might do the trick, though I couldn’t find any clear indication of where and how to implement it.

Hope you can help!

This is my current collection code:

{
  "sections": {
    "product-grid": {
      "type": "main-collection-product-grid",
      "settings": {
        "products_per_page": 40,
        "image_ratio": "adapt",
        "show_secondary_image": false,
        "add_image_padding": false,
        "show_image_outline": false,
        "show_vendor": false,
        "show_rating": false,
        "enable_filtering": true,
        "enable_sorting": true,
        "collapse_on_larger_devices": false
      }
    }
  },
  "order": [
    "product-grid"
  ]
}

Hello there, try to change this value: “products_per_page”: 40, try to change 40 to any other number to see is working or not.

Thanks for the reply.

I think that would just limit the page size, though by scrolling down it would reveal the rest of the products.

Please correct me if I am wrong.

I am also looking on how to limit a collection to a certain number of items. I tried

{%- for product in collection.products limit:20 -%} but this also only limits the products to the page rather than to the entire collection.

1 Like

Did you find an answer to this?