Skip to content

Instantly share code, notes, and snippets.

@zourite
Last active April 11, 2020 20:20
Show Gist options
  • Save zourite/62a3f2ca8f07f99114a7a030cc109693 to your computer and use it in GitHub Desktop.
Save zourite/62a3f2ca8f07f99114a7a030cc109693 to your computer and use it in GitHub Desktop.
Custom pagination for Hugo based on this post => https://glennmccomb.com/articles/how-to-build-custom-hugo-pagination/
{{ $paginator := .Paginator }}
<!-- If there's more than one page. -->
{{ if gt $paginator.TotalPages 1 }}
<ul class="pagination center">
<!-- Previous page. -->
{{ if $paginator.HasPrev }}
<li>
<a href="{{ $paginator.Prev.URL }}">
«
</a>
</li>
{{ end }}
<!-- First page. -->
<li class="{{ if eq $paginator.PageNumber 1 }} active {{ end }} waves-effect">
<a href="{{ $paginator.First.URL }}">
1
</a>
</li>
<!-- Page numbers. -->
{{ range after 1 $paginator.Pagers}}
<li class="{{ if eq . $paginator }} active {{ end }} waves-effect">
<a href="{{ .URL }}" class="pagination__link">
{{ .PageNumber }}
</a>
</li>
{{ end }}
<!-- Next page. -->
{{ if $paginator.HasNext }}
<li>
<a href="{{ $paginator.Next.URL }}">
»
</a>
</li>
{{ end }}
<!-- Last page. -->
<!-- {{ if ne $paginator.PageNumber $paginator.TotalPages }}
<li class="pagination__item pagination__item--last">
<a class="pagination__link pagination__link--last" href="{{ $paginator.Last.URL }}">
»»
</a>
</li>
{{ end }} -->
</ul><!-- .pagination -->
{{ end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment