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.
1 {%- set Begin = paginator.current_index -4 -%}
2 {%- set End = paginator.current_index +5 -%}
3 {%- if Begin <= 0 -%}
4 {%- set Begin = 1 -%}
5 {% set End = 10 %}
6 {%- endif -%}
7 {%- if End >= paginator.number_pagers -%}
8 {%- set Begin = paginator.number_pagers - 10
9 -%}
10 {%- set End = paginator.number_pagers -%}
11
12 {%- endif -%}
13 {% for P in range(start=Begin, end=End) -%}
14
15 {%- if P == paginator.current_index-%}
16 {% set T = '<li class="page-prev">'~ paginator.current_index~'</li>' %}
17 {% set_global Nav = Nav~T %}
18 {%- else -%}
19 {% set T = '<li class="page-prev"><a href="'~ paginator.base_url~P~'/" title="Goto page '~P~'">' ~P~'</a></li>' %}
20 {%- set_global Nav = Nav~T -%}
21 {%- endif %}
22 {%- endfor -%}
23
24 {%- if paginator.next-%}
25 {% set TheIndex = paginator.current_index +1 %}
26
27 {% set T = '<li class="page-prev"><a href="'~ paginator.next~'" title="First Page (Page '~ TheIndex ~'">Next</a></li>' %}
28 {% set Nav = Nav~T %}
29 {%- endif -%}
Feel free to adapt this and use this if it’s helpful to you.