简体   繁体   English

相关产品Shopify Liquid

[英]Related Products Shopify Liquid

I'm trying to determine the correct Shopify Liquid syntax for outputting a list of products that match the same tag as the current product. 我试图确定正确的Shopify Liquid语法,以输出与当前产品匹配相同标签的产品列表。

This is to appear in a "Related Products" box on the product page, and I'd like it only to list other products that match the same tag of the current product page. 这将出现在产品页面的“相关产品”框中,我只希望列出与当前产品页面的相同标签匹配的其他产品。

Unfortunately the Related Products wiki page didn't help me with this. 不幸的是, 相关产品wiki页面对此没有帮助。

I'm not sure you can get a set of all products with a common tag (although I may be wrong) but here's a possible alternative way to approach it - create a smart collection of products that contain that tag, then output the products from that collection in the related items area. 我不确定您能否获得所有带有通用标签的产品(尽管我可能错了),但是这是一种可行的替代方法-创建包含该标签的智能产品集合,然后从中输出产品相关项目区域中的该集合。

To connect the product tag to the right collection on the product page, make sure that your collection handle is the same as the tag you're using, then do something like this to grab the right collection based on the tag. 要将产品标签连接到产品页面上的正确收藏,请确保您的收藏句柄与您所使用的标签相同,然后执行类似的操作以根据标签获取正确的收藏。

{% for c in collections %}
  {% assign t = {{product.tags[0] | handleize}} %}
  {% if c.handle == t %}
    {% assign collection = c %}
  {% endif %} 
{% endfor %}

Then just output the products in the collection using the approach outlined in the wiki article you linked. 然后,使用您链接的Wiki文章中概述的方法,仅输出集合中的产品。

Something like this (assuming you use a "product-loop" include approach) should do the trick: 这样的事情(假设您使用“产品循环”包含方法)应该可以解决问题:

{% assign current_product = product %}
{% assign current_product_found = false %}
{% for product in collection.products %}
  {% if product.handle == current_product.handle %}
    {% assign current_product_found = true %}
  {% else %}
    {% unless current_product_found == false and forloop.last %}
      {% include 'product-loop' with collection.handle %}
    {% endunless %}
  {% endif %}
{% endfor %}

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

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