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
…