Last active
October 22, 2020 00:11
-
-
Save UbaldoRosas/63c0af13cec29a00fec24cb41799e4d6 to your computer and use it in GitHub Desktop.
Shopify pagination links with pages range. Currently shows 3 pages more and 3 pages less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% assign current_page = paginate.current_page %} | |
{% assign max_limit_pages = current_page | plus: 3 %} | |
{% assign min_limit_pages = current_page | minus: 4 %} | |
<div id="pagination"> | |
<ul id="pagination-list"> | |
{% if paginate.previous %} | |
<li id="pagination-prev" class="pagination-button"> | |
{% unless paginate.previous.is_link %} | |
<div class="btn btn--secondary btn--narrow btn--disabled"> | |
{% include 'icon-arrow-left' %} | |
<span class="icon__fallback-text">{{ 'general.pagination.previous' | t }}</span> | |
</div> | |
{% else %} | |
<a href="{{ paginate.previous.url }}" class="btn btn--secondary btn--narrow"> | |
{% include 'icon-arrow-left' %} | |
<span class="icon__fallback-text">{{ 'general.pagination.previous' | t }}</span> | |
</a> | |
{% endunless %} | |
</li> | |
{% endif %} | |
{% for i in (1..paginate.pages) %} | |
{% if i > 0 and i < current_page and i > min_limit_pages %} | |
<li class="pagination-page minus"><a href="?page={{ i }}">{{ i }}</a></li> | |
{% endif %} | |
{% if current_page == i %} | |
<li id="pagination-current" class="pagination-page">{{ i }}</li> | |
{% endif %} | |
{% if i <= max_limit_pages and i > current_page %} | |
<li class="pagination-page"><a href="?page={{ i }}">{{ i }}</a></li> | |
{% endif %} | |
{% endfor %} | |
{% if paginate.next %} | |
<li id="pagination-next" class="pagination-button"> | |
{% unless paginate.next.is_link %} | |
<div class="btn btn--secondary btn--narrow btn--disabled"> | |
{% include 'icon-arrow-right' %} | |
<span class="icon__fallback-text">{{ 'general.pagination.next' | t }}</span> | |
</div> | |
{% else %} | |
<a href="{{ paginate.next.url }}" class="btn btn--secondary btn--narrow"> | |
{% include 'icon-arrow-right' %} | |
<span class="icon__fallback-text">{{ 'general.pagination.next' | t }}</span> | |
</a> | |
{% endunless %} | |
</li> | |
{% endif %} | |
</ul> | |
</div> |
I literally spent three hours trying to figure this exact thing out. Thanks so much!!
You're welcome! ;))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I literally spent three hours trying to figure this exact thing out. Thanks so much!!