Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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!
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024