html 标签相关产品 - 添加到product.liquid

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 标签相关产品 - 添加到product.liquid相关的知识,希望对你有一定的参考价值。

<!-- Solution brought to you by Caroline Schnapp -->
<!-- See this: http://wiki.shopify.com/Related_Products -->

{% assign image_size = 'compact' %}
{% assign heading = 'Other fine products' %}

{% if product.tags.size > 0 %}

<h3>{{ heading }}</h3>
<ul class="related-products"></ul>

<style type="text/css">
.related-products { list-style-type:none }
{% case image_size %}
{% when 'small' %}
.related-products * { font-size:12px; text-align:center; padding:0 }
.related-products h4  { border:none; margin:10px 0 0 0; line-height:1.3 }
.related-products div.image { height:100px }
.related-products li { float:left; width:120px; height:160px; margin-right:20px }
{% when 'compact' %}
.related-products * { font-size:13px; text-align:center; padding:0 }
.related-products h4  { border:none; margin:5px 0 0 0; line-height:1.5 }
.related-products div.image { height:160px }
.related-products li { float:left; width:180px; height:220px; margin-right:25px }
{% when 'medium' %}
.related-products * { font-size:14px; text-align:center; padding:0 }
.related-products h4  { border:none; margin:10px 0 0 0; line-height:1.8 }
.related-products div.image { height:240px }
.related-products li { float:left; width:260px; height:300px; margin-right:25px }
{% endcase %}
.related-products { overflow:hidden }
.related-products span.money { font-size:0.8em }
.related-products li:last-child { margin-right:0 }
</style>

<script>!window.jQuery && document.write('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"><\/script>')</script>
{{ 'api.jquery.js' | shopify_asset_url | script_tag }}

<script type="text/javascript" charset="utf-8">
//<![CDATA[
  var recommendations = [];
  {% for tag in product.tags %}
  recommendations.push('{{ tag | handle }}');
  {% endfor %}
  if (recommendations.length) {
    var list = jQuery('ul.related-products');
    for (var i=0; i<recommendations.length; i++) {
      jQuery.getJSON(recommendations[i] + '.js', function(product) {
        list.append('<li><div class="image"><a href="' + product.url +'"><img src="' + product.images[0].replace(/(\.jpg|\.png|\.jpeg|\.gif)/, '_{{ image_size }}$1') + '" /></a></div><h4><a href="' + product.url + '">' + product.title + '</a></h4><span class="money">' + Shopify.formatMoney(product.price, "{{ shop.money_format }}") + '</span></li>');
      });
    }
  }
//]]>
</script>

{% endif %}

以上是关于html 标签相关产品 - 添加到product.liquid的主要内容,如果未能解决你的问题,请参考以下文章

如何以编程方式将标签插入woocommerce产品

相关产品仅限于WooCommerce 3中的标签,而不是类别

在常规单个产品页面的自定义选项卡中显示“相关产品”

标签的加权聚类

将分类术语添加到 WooCommerce 产品永久链接

在商店页面上将 ACF 添加到 Woocommerce ul.products