Last active
November 2, 2023 11:07
-
-
Save IliasDeros/10cbdf4b6ba9e610ae82d725bff7d56f to your computer and use it in GitHub Desktop.
Shopify: Show all numbers in pagination, retaining query parameters. Inspired by: https://gist.github.com/kyleaparker/7588995
This file contains hidden or 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
{% for part in (1..paginate.pages) %} | |
{% if forloop.index == 1 %} | |
{% if paginate.next.is_link %} | |
{%- assign next_page = current_page | plus: 1 -%} | |
{%- assign page_query_param_old = 'page=' | append: next_page -%} | |
{%- assign page_url_template = paginate.next.url -%} | |
{% elsif paginate.previous.is_link %} | |
{%- assign previous_page = current_page | minus: 1 -%} | |
{%- assign page_query_param_old = 'page=' | append: previous_page -%} | |
{%- assign page_url_template = paginate.previous.url -%} | |
{% else %} | |
{%- assign page_query_param_old = 'page=page' -%} | |
{%- assign page_url_template = collection.url | append: '?page=page' -%} | |
{% endif %} | |
{% endif %} | |
{%- assign page_query_param_new = 'page=' | append: forloop.index -%} | |
{%- assign page_url = page_url_template | replace: page_query_param_old, page_query_param_new -%} | |
<li class="page {% if paginate.current_page == part %}current{% endif %}"> | |
<a class="page__number" href="{{ page_url }}">{{ forloop.index }}</a> | |
</li> | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this code. It really helped.