Liquid, JavaScript, themes, sales channels
Is there a way to have this select the second image in the product images, instead of the first one?
Thank you!
<a href="{{ item.url | within: collections.all }}" class="thumbnail">
<figure class="lazy-image {% if item.image.src contains 'png' %} lazy-image--transparent {% endif %}" data-ratio style="padding-top: 130%">
<img
src="{{ item.image | img_url: '100x130', crop: 'center' }}" alt="{{ item.title | escape }}"
srcset="{{ item.image | img_url: '100x130', crop: 'center' }} 100w, {{ item.image | img_url: '200x260', crop: 'center' }} 260w"
sizes="100px" class="img lazy"
loading="lazy"
width="{{ item.image.width }}" height="{{ item.image.height }}"
/>
</figure>
Solved! Go to the solution
This is an accepted solution.
Hi @kristobar,
Please change all code:
<a href="{{ item.url | within: collections.all }}" class="thumbnail">
{% assign image_product = item.product.media[1] %}
<figure class="lazy-image {% if image_product.src contains 'png' %} lazy-image--transparent {% endif %}" data-ratio style="padding-top: 130%">
<img
src="{{ image_product | img_url: '100x130', crop: 'center' }}" alt="{{ item.title | escape }}"
srcset="{{ image_product | img_url: '100x130', crop: 'center' }} 100w, {{ image_product | img_url: '200x260', crop: 'center' }} 260w"
sizes="100px" class="img lazy"
loading="lazy"
width="{{ image_product.width }}" height="{{ image_product.height }}"
/>
</figure>
Hope it helps!
This is an accepted solution.
Hi @kristobar,
Please change all code:
<a href="{{ item.url | within: collections.all }}" class="thumbnail">
{% assign image_product = item.product.media[1] %}
<figure class="lazy-image {% if image_product.src contains 'png' %} lazy-image--transparent {% endif %}" data-ratio style="padding-top: 130%">
<img
src="{{ image_product | img_url: '100x130', crop: 'center' }}" alt="{{ item.title | escape }}"
srcset="{{ image_product | img_url: '100x130', crop: 'center' }} 100w, {{ image_product | img_url: '200x260', crop: 'center' }} 260w"
sizes="100px" class="img lazy"
loading="lazy"
width="{{ image_product.width }}" height="{{ image_product.height }}"
/>
</figure>
Hope it helps!
Wow thank you!
Would it be possible to add a part that checks if the product has more than one image to select the second one?
Sorry to bug you again
Hi @kristobar,
Please change all code:
<a href="{{ item.url | within: collections.all }}" class="thumbnail">
{% if item.product.media[1] %}
{% assign image_product = item.product.media[1] %}
{% else %}
{% assign image_product = item.image %}
{% endif %}
<figure class="lazy-image {% if image_product.src contains 'png' %} lazy-image--transparent {% endif %}" data-ratio style="padding-top: 130%">
<img
src="{{ image_product | img_url: '100x130', crop: 'center' }}" alt="{{ item.title | escape }}"
srcset="{{ image_product | img_url: '100x130', crop: 'center' }} 100w, {{ image_product | img_url: '200x260', crop: 'center' }} 260w"
sizes="100px" class="img lazy"
loading="lazy"
width="{{ image_product.width }}" height="{{ image_product.height }}"
/>
</figure>
Thank you so much!
Hi @kristobar,
I saw you liked my answer. If it helped you solve your issue, please mark it as a solution. Thank you and good luck.
Hello, is it possible to have that feature just on one "landing page". So in the normal Shop it shows the first image as a thumbnail and on a specific page with featured Products it shows the second image? Maybe over custom css?
Thanks in advance!
User | RANK |
---|---|
37 | |
28 | |
13 | |
13 | |
9 |
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023