Filter items in collection with images?

Highlighted
Explorer
42 10 12

Hi Guys,

I want to filter a collection to show only items that have images. So I can use this to paginate instead of the entire collection.

is there a way to filter a collection like this?

I have a collection page where the first thing I do is paginate  using collection products.

 

{% paginate collection.products by 20  %}

 

 

The page then loops through all the items and creates product cards like a regular ecom website.

I wanted to remove the possibility of items without images from appearing on the site

So during the loop I check to see if the item has an image. And if it doesn't I'll just skip it

{% if product.available and product.images.size > 0 %}

 

The problem im having is at the top I paginate by the entire collection. And the way I'm filtering out imageless items is wrong because it'll still render the page as if the items were there, I could have 5 pages of nothing.

 

0 Likes