我要在网站上设置一个新部分,当在产品下面选择一个产品时,我的部分显示了相同品牌的产品,现在我有150多个具有相同品牌的产品,但是我只显示5个,我想显示每次加载页面时,都会随机抽取5个具有相同品牌的产品,我该如何实现?
{% assign collection_title = collection.handle %}
{% assign vendor = product.vendor %}
{% assign product_handle = product.handle %}
{% assign counter = '' %}
{% assign relatedCollection = collections['all'].all_products %}
{% assign index = 'now' | date: '%S' %}
{% assign index = index | times: relatedCollection.products.size %}
{% assign index = index | divided_by: 60 %}
{% for product in collections['all'].all_products offset: index %}
{% if vendor == product.vendor and counter.size < 5 and product_handle
!= product.handle %}
{% capture temp %}{{ counter }}*{% endcapture %}
{% assign counter = temp %}
{% include 'product-grid-item' %}
{% endif %}
{% endfor %}