This guide will help you to add next/previous links to your product page. In this way, you will be able to navigate through the different products of each collection.
Example of the next/previous buttons' functionality
- Access your themes section
- Open the Loft theme code
- Add code
1. Access your themes section
Login to your Shopify admin, and then click “Online Store” (on the left side of the admin). This takes you to the “themes” area of your Shopify store.
Example themes section
2. Open the Loft theme code
Next, click the button that says “Actions” - followed by “Edit code” which will load the live code editor. It consists of a left hand sidebar, which lists all the files on Loft, along with a right hand code editing panel.
Shopify code editor
3. Add code
You need to add a few lines of code to the product-details.liquid by doing the following steps:
- Search for the "Snippets" folder
- Open the "product-details.liquid" file
- On line 32, below the "{%endif%}", add the following block of code
{% assign nextprevCount = 0 %}
{% if collection.previous_product%}
{% assign nextprevCount = nextprevCount | plus: 1 %}
<strong><span> <a href="{{collection.previous_product.url}}" class="nextprev"><Previous Product</a></span></strong>
{% endif %}
{% if collection.next_product %}
{% assign nextprevCount = nextprevCount | plus: 1 %}
<strong><span> <a href="{{collection.next_product.url}}" class="{% if nextprevCount == 2%}leftmarg{%endif%} nextprev">Next Product></a></span></strong>
{% endif%}Before
After
- Add the following block of code to the end of the file
<style> .nextprev {
text-decoration: none;
color: black;
display: inline-block;
margin-top: 15px;
}
.leftmarg{
margin-left: 2em;
} .hovsymb:hover{
color: #ea9e33;
} </style> - Click "Save"