我在Shopify有一个集合,我想只显示4个产品。然后,如果用户单击按钮以展开并查看更多集合,则会显示该集合的其余部分。目前我只是将集合限制为4,我想要找到的是一种方法,使链接填充其余的集合。不确定使用2个不同的集合是否更好,而不是以这种方式进行限制。这是我目前的代码:
<ul id="collection-grid" class="product-grid">
{% assign collectionName = 'featured-products' %}
{% for product in collections.featured-products.products limit:4 %}
<div class="grid_left">
{% include 'product-grid-item' %}
</div><!-- end of grid_left -->
{% endfor %}
</ul>
<div class="expand_selection">
<a href=""><img src="http://cdn.shopify.com/s/files/1/0173/1766/files/expand.gif" alt="Expand" /></a> Click to expand for more supplements...
</div><!-- end of expand_selection -->
答案 0 :(得分:2)
您可以使用隐藏的<div>
和一些javascript(我为了简单起见使用了jQuery),例如:
{% for product in collections.featured-products.products limit:4 %}
<!-- first 4 products -->
{% endfor %}
<a href="#" onclick="jQuery("#rest_of_collection").show()">show all products</a>
<div id="rest_of_collection" style="display:none">
{% for product in collections.featured-products.products offset:5 %}
<!-- other products -->
{% endfor %}
</div>