How to limit the number of links in Pagination?

Hi everyone! Are you all ok?

I have a question. I don’t know if it’s possible. Right now I have this in the end of the page «« « 1 2 3 4 5 6 7 8 9 » »», but I just want 5 links like this «« « 1 2 3 4 5 » »» and then «« « 2 3 4 5 6 » »». Is there some way to limit the number of links?

Thank you all!

Not in the built-in paginator template, but you should be able to build it yourself using PageNumber and the other attributes, see the docs.

A conditional, maybe a counter. It’s called programming.

I will see. Thank you!

I needed this today and this is what I ended up using:

`

      {{ $pag := $.Paginator }}
          {{ if gt $pag.TotalPages 1 }}
          <ul class="pagination">
              {{ with $pag.First }}
              <li>
                  <a href="{{ .URL }}" aria-label="First"><span aria-hidden="true">&laquo;&laquo;</span></a>
              </li>
              {{ end }}
              <li
              {{ if not $pag.HasPrev }}class="disabled"{{ end }}>
              <a href="{{ if $pag.HasPrev }}{{ $pag.Prev.URL }}{{ end }}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a>
              </li>
              {{ range $index, $element := $pag.Pagers }}
              {{ $less := lt (sub $pag.PageNumber $index) 4 }}
              {{ $more := gt (sub $pag.PageNumber $index) -4 }}
              {{ if and $less $more }}
              <li
              {{ if eq $element $pag }}class="active"{{ end }}><a href="{{ $element.URL }}">{{ $element.PageNumber }}</a></li>
              {{ end }}
              {{ end }}

              <li
              {{ if not $pag.HasNext }}class="disabled"{{ end }}>
              <a href="{{ if $pag.HasNext }}{{ $pag.Next.URL }}{{ end }}" aria-label="Next"><span aria-hidden="true">&raquo;</span></a>
              </li>
              {{ with $pag.Last }}
              <li>
                  <a href="{{ .URL }}" aria-label="Last"><span aria-hidden="true">&raquo;&raquo;</span></a>
              </li>
              {{ end }}
          </ul>
          {{ end }}



    </div>`
2 Likes