hugo-stanley/layouts/partials/pagination.html

34 lines
1.1 KiB
HTML
Raw Permalink Normal View History

2020-03-03 18:56:59 +01:00
{{- $paginator := . -}}
{{- if gt $paginator.TotalPages 1 -}}
{{- $pageIndex := $paginator.PageNumber -}}
{{- $totalPages := $paginator.TotalPages -}}
{{- $cols := 5.0 -}}
{{- $rows := math.Ceil (div $totalPages $cols) -}}
{{- $row := math.Ceil (div $pageIndex $cols) -}}
{{- $startPage := sub (mul $row $cols) $cols -}}
{{- $endPage := add $startPage $cols -}}
<div class="pagination">
<ul>
{{- if gt $row 1 -}}
<li><a href="{{- $paginator.Prev.URL -}}" class="previous_page">&laquo;</a></li>
{{- end -}}
{{- range $paginator.Pagers -}}
{{- if and (gt .PageNumber $startPage) (le .PageNumber $endPage) -}}
{{- $active := "" -}}
{{- if eq .PageNumber $paginator.PageNumber -}}
{{- $active = "active" -}}
{{- end -}}
<li><a class="{{- $active -}}" href="{{- .URL -}}">{{- .PageNumber -}}</a></li>
{{- end -}}
{{- end -}}
{{- if lt $row $rows -}}
<li><a href="{{- $paginator.Next.URL -}}" class="next_page">&raquo;</a></li>
{{- end -}}
</ul>
</div>
{{- end -}}