简体   繁体   English

Shopify-精选图片在收藏夹视图中复制了产品

[英]Shopify - Featured image duplicates product in collection view

When displaying an image in the collection section and having product preview images associated with a certain product, I receive duplicate copies of the product because I have image previews. 在“收藏”部分中显示图像并让某个产品与产品预览图像相关联时,由于具有图像预览,因此我会收到该产品的重复副本。 Is this because I'm not calling for the first featured image? 这是因为我不要求第一张特色图片吗?

<img src="{{ collection.products.first.featured_image | product_img_url: 'medium' }}">

在此处输入图片说明

Both images go to the same product. 两个图像都使用相同的产品。 I figured out that because I have a preview image and a featured image it displays two identical products. 我发现,因为我有一个预览图像和一个特色图像,所以它显示两个相同的产品。

Here's the full source: 这是完整的源代码:

<div class="collectionfront">   
{% for product in products %}
{% for image in product.images %}
<a href="/products/{{ product.handle }}" class="product-hover"><img src="{{ collection.products.first.featured_image | product_img_url: 'medium' }}"><h2><span>{{ product.title }}</span></h2>{{ product.price | money_with_currency }}{% if product.available %}<form action="/products/{{ product.handle }}"><span><button type="submit" class="shop-btn">Shop</button></span></form>{% else %}<p>Sold Out!</p>{% endif %}</a>
{% endfor %}

{% endfor %} 
</div>

I think it's because you're looping through each product image. 我认为这是因为您要遍历每个产品图片。 Try removing your inner for loop {% for image in product.images %} . 尝试删除您的内部for循环{% for image in product.images %}

Also, if you are displaying a featured image for a product and not a collection, you probably want product.featured_image instead of collection.products.first.featured_image . 另外,如果要显示产品的特色图像而不是集合,则可能需要product.featured_image而不是collection.products.first.featured_image

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM