javascript - Cycle through all products within a collection | SHOPIFY -


running issues adjusting 'previous product' , 'next product' functionality within shopify.

i'd set 'previous' , 'next' loops through products, carousel style.

once you're @ last product,'next' take first. @ moment, once reach end, can go previous product , backwards through list.

any thoughts?

here's base code:

  {% if collection.previous_product %}       {{ '«' | link_to: collection.previous_product }}    {% endif %}    {% if collection.next_product %}      {% if collection.previous_product %} | {% endif %}      {{ '»' | link_to: collection.next_product }}    {% endif %} 

try this:

{% if collection.previous_product %}   {{ '«' | link_to: collection.previous_product }} {% else %}   {% assign last_product_url = collection.products.last.url | within:collection %}   {{ '«' | link_to: last_product_url }} {% endif %}  {% if collection.next_product %}   {{ '»' | link_to: collection.next_product }} {% else %}   {% assign first_product_url = collection.products.first.url | within:collection %}   {{ '»' | link_to: first_product_url }} {% endif %} 

if have more 50 products in collection, should note collection.products paginated.

see here info on within filter.