Shopify-如何从多个上传产品中调用特定的元场
我创建了一个“产品参考”和“产品列表” metafield
。这使我可以将多个产品添加到我制作的metafield
中。我要做的是显示我添加的产品的图像和标题,但是我想做的就是能够访问我添加的每种产品。
例如,我在metafield
部分中添加了两个产品,但我只想在我的产品页面上显示其中一个。
我想单独访问我的产品的原因是我将使用Bootstrap,并且我想将每个产品图片分别添加到创建的Divs。
这是我试图调用我的metafield
的代码的样子。 (它带来了这两张图片)
{% if product.metafields.my_fields.custom_img.value != blank %}
<h3>Recommended Products</h3>
{% assign recommended_products = product.metafields.my_fields.custom_img.value %}
{% for product in recommended_products %}
<a href="{{ product.url }}">
{{ product.featured_image | image_url: width: 400 | image_tag }}
</a>
{% endfor %}
{% endif %}
I created a "Product Reference" and "List of products" metafield
. This allows me to add multiple products into the metafield
that I made. What I'm trying to do is display images and titles of the products that I added but what I would like to do is able to access each of the products I added.
For example, I have added two products to my metafield
section but I only want to display one of them on my product page.
The reason why I would like to access my products individually is I'm going to use bootstrap and I want to add each product picture individually to the divs I created.
Here's what my code looks like when I'm trying to call my metafield
. (It brings both of the pictures)
{% if product.metafields.my_fields.custom_img.value != blank %}
<h3>Recommended Products</h3>
{% assign recommended_products = product.metafields.my_fields.custom_img.value %}
{% for product in recommended_products %}
<a href="{{ product.url }}">
{{ product.featured_image | image_url: width: 400 | image_tag }}
</a>
{% endfor %}
{% endif %}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只想显示第一个最简单的方法是这样做
显示特定产品
,或者如果您想对Cylce Liquid拥有更多控制权,则要 =“ https://shopify.dev/api/liquid/objects/for-loops” rel =“ nofollow noreferrer”> https://shopify.dev/api/liquid/liquid/objects/for-lo-lo-lo-lo-lo-lor-loops
例如您也可以这样做
以显示前两个产品。
If you want to display only the first the easiest way is to do
Or if you want to display a particular product
If you want to have more control over the for cylce liquid offers you the
forloop
object https://shopify.dev/api/liquid/objects/for-loopsFor example you could also do
to display the first 2 products.
您可以像液体中的任何列表一样访问您创建的Metafield,例如,如果您想访问列表中的第一个产品
,或者可以访问列表中的任何特定产品:
You can access the metafield that you've created just like any list in liquid, for example, if you want to access the first product in the list you can do
Or you can access any specific product in the list like so: