Shopify themes, liquid, logos, and UX
Hi
I'm using the Minimalista theme to build a website for a client, and on each product page I'd like to add a "Previous" and "Next" button to navigate to the other products within the collection. It doesn't seem to be possible within the theme, so can anyone help me with the code for this?
Thanks in advance!
Harry
Hi @harry-w
You can try something like this
{%- assign collection = collection | default: product.collections.first -%}
{%- if collection -%}
{%- for product in collection.products -%}
{%- if product.handle == product.handle -%}
{%- assign index = forloop.index0 -%}
{%- assign prev_index = index | minus: 1 -%}
{%- assign next_index = index | plus: 1 -%}
{%- if prev_index >= 0 -%}
{%- assign prev_product = collection.products[prev_index] -%}
<a href="{{ prev_product.url }}" class="prev-product">← Previous</a>
{%- endif -%}
{%- if next_index < collection.products.size -%}
{%- assign next_product = collection.products[next_index] -%}
<a href="{{ next_product.url }}" class="next-product">Next →</a>
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
<style>
.prev-product, .next-product {
display: inline-block;
padding: 8px 12px;
background-color: #000;
color: #fff;
text-decoration: none;
border-radius: 5px;
margin: 10px;
}
.prev-product:hover, .next-product:hover {
background-color: #333;
}
</style>
Thanks!
OK — I'll do some experimenting and get back to you if I have more questions.
Thanks again for the input, I really appreciate it!
Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025