Reverse order pages in pagination template

Assume I have 10 posts, named Post 1, Post 2 etc, and posted in chronological order so that the publishdate param for the posts is earliest for Post 1 and most recent for Post 10.

The code below shows 5 posts per page, and on each page the posts are ordered from oldest to newest, which is what I want

However, the pagination navigation template groups the posts from the most recent first, so that page 1 has Post 6 to Post 10 and page 2 has Post 1 to Post 5.

Is there a way to order the pages so that page 1 has Post 1 to Post 5 and page 2 has Post 6 to Post 10?

{{ $pages := ((.Paginator 5).Pages.ByParam "publishdate")}}
{{ range $pages }}
    {{ .Render "list_item" }}
{{ end }}
{{ template "_internal/pagination.html" . }}

First, you can use the ByPublishDate method instead of .ByParam "publishdate".

Second, instead sorting a paginated collection, you need to paginate a sorted collection. For example:

{{ range (.Paginate .Pages.ByPublishDate 5).Pages }}
  ...
{{ end }}

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.