Zola Pagination With Go To Page
I have been wanting to add some go to pages to my pagination section of navigation for a while. I just haven’t looked into doing it until today.
It was pretty straightforward once I went though the documentation a bit.
Here’s how I did it.
{%- set Begin = paginator.current_index -4 -%}
{%- set End = paginator.current_index +5 -%}
{%- if Begin <= 0 -%}
{%- set Begin = 1 -%}
{% set End = 10 %}
{%- endif -%}
{%- if End >= paginator.number_pagers -%}
{%- set Begin = paginator.number_pagers - 10
-%}
{%- set End = paginator.number_pagers -%}
{%- endif -%}
{% for P in range(start=Begin, end=End) -%}
{%- if P == paginator.current_index-%}
{% set T = '<li class="page-prev">'~ paginator.current_index~'</li>' %}
{% set_global Nav = Nav~T %}
{%- else -%}
{% set T = '<li class="page-prev"><a href="'~ paginator.base_url~P~'/" title="Goto page '~P~'">' ~P~'</a></li>' %}
{%- set_global Nav = Nav~T -%}
{%- endif %}
{%- endfor -%}
{%- if paginator.next-%}
{% set TheIndex = paginator.current_index +1 %}
{% set T = '<li class="page-prev"><a href="'~ paginator.next~'" title="First Page (Page '~ TheIndex ~'">Next</a></li>' %}
{% set Nav = Nav~T %}
{%- endif -%}
Feel free to adapt this and use this if it’s helpful to you.