Shopify商品置顶功能

Shopify商品置顶功能

商品置顶功能描述:通过在商品列表页为链接添加参数的方法实现置顶某个或多个商品的功能。

需按以下步骤将目标代码添加到目标位置
目标代码

    <!-- 置顶商品的展示开始 -->
          {% assign handles = '' %}
          {% assign handleSize = 0 %}
          {% if current_page == 1 %}
            {% assign handles = collection.sort_by | downcase | replace:'%2C',',' | replace:'%2c',',' | split: ',' %}
            {% for handle in handles %}
            {%- assign product = all_products[handle] -%}
            {% if product != empty %}
              {% assign handleSize = handleSize|plus: 1 %}
              {% assign featured = product %}
              {% include 'product-grid-item' %}
            {% endif %}
            {% endfor %}
          {% endif %}
       <!-- 置顶商品的展示结束 -->
          
       <!-- 其余商品的展示开始 -->
          {%- for product in collection.products -%}
          {% if handles contains product.handle %}
            {% continue %}
          {% else %}
            {% assign productIndex = productIndex | plus: 1 %}
            {% if productIndex > productSize %}
              {% continue %}
            {% else %}
              {% assign featured = product %}
			{% include 'product-grid-item' %}
             {% endif %}
          {% endif %}
          {%- endfor -%}
       <!-- 其余商品的展示结束 -->

目标位置查找方法
打开shopify后台 – 依次点击 Online Store – Actions – Edit Code – 搜索并打开colletion-template.liquid。

将目标代码替换掉原始代码

多个商品的置顶
多个商品的置顶和之前保持⼀致,⽤英⽂状态下的 " , " 进⾏分割即可

形成初步置顶链接
复制某个类⽬的链接,并将上边获取到的handle属性准备好,⽤ sort_by= 进⾏拼接即可,如下所示是⼀个示例连接:
https://www.xxxxx.com/collections/best-seller?sort_by=ladfew58-chibb1

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值