php - Shopify 标签总数

标签 php shopify

在 Shopify 中,如何显示标签列表以及带有该标签的产品数量?

示例:黑色(12)、蓝色(10)。

目前代码看起来像这样,但它不起作用。

<ul>
    {% for tag in collection.all_tags %}
        <li>
            <a href="https://mystore.myshopify.com/collections/all/{{ tag }}">
                {{ tag }}
            </a>
            ({{ tag.products_count }})
        </li>
    {% endfor %}
</ul>

最佳答案

products_countcollection 的属性,而不是标签

我相信您需要手动循环浏览产品并计算具有指定标签的数量。

例如:

{% assign collection = collections.all %}

<ul>
    {% for tag in collection.all_tags %}

        {% assign products_count = 0 %}
        {% for product in collection.products %}
            {% if product.tags contains tag %}
                {% assign products_count = products_count | plus: 1 %}
            {% endif %}
        {% endfor %}

        <li>
            <a href="https://mystore.myshopify.com/collections/all/{{ tag }}">
                {{ tag }}
            </a>
            ({{ products_count }})
        </li>
    {% endfor %}
</ul>

查看 Shopify 论坛上的这些类似讨论:

关于php - Shopify 标签总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24031787/

相关文章:

javascript - 模板脚本使其仅对 Shopify 上的管理员可见

javascript - 保护 PHP 脚本 - Shopify

php - 在 NetBeans 中对 false、true、null 使用小写常量

php - 在 php 中为 filter_var 指定回调参数

php - Woocommerce 中的 Ajaxify header 购物车项目计数

javascript - axios({method : "post"}) and axios. post()的区别

php - 显示第三个表中的字段

php - CakePHP动态路由配置,可能吗?或者只是一个梦想?

php - 使用 cURL 将商品添加到 Shopify 购物车

python - 如何使用 Shopify Python API RecurringApplicationCharge