Reverse order of paginated content by date

Hey all. I’ve looked over pagination code via Google, blog posts, and through this forum and I can’t seem to find an answer to a simple problem. All I want is for the paginated pages to have the newest (by date) on the first page, and have the oldest content on the last page.

{{ define "content" }}
<main class="notes">
{{ $posts := where .Site.RegularPages "Section" "notes" }}
{{ $paginator := .Paginate $posts.ByDate.Reverse }}
  <header>
    {{ .Content }}
  </header>
  {{ range $paginator.Pages }}
  {{ $t := .Date }}
  {{ $t = time.AsTime $t }}
  {{ $format := "Jan 02, 2006" }}
  <article class="note">
    <a href="{{ .Permalink }}">
      <time>{{ $t.UTC.Format $format }}</time>
    </a>
    {{ .Content }}
  </article>
  {{ end }}
  <footer>
    {{ partial "pagination.html" . }}
  </footer>
</main>
{{ end }}

I’ve played around with the contents of $posts :=, $paginator :=, and the range lines in various combinations using .ByDate, .ByPublishedDate, and .Reverse with no luck in actually getting it to render in reverse chronological order. What am I missing?

I also have disableAliases set to true, if that matters at all.

As I am aware, thats the default approach on pagination. Please share your code ilustrating the issue you facing so somebody can help you.

1 Like

I took a closer look as you said it should be the default behavior. I noticed it was working properly for one content type and saw the markup was actually different. After matching it it’s working now.

I figured it out by myself basically, but thank you all anyway.