Previous and Next page sorting by date, is it possible?

Hi,

The .Prev and .Next functions use the default sorting order, so first by weight then by date, etc. Can I somehow change the sorting order for these functions. .Prev.ByDate doesn’t work.

See https://gohugo.io/variables/pages/

I’ve read the page a few times, and I’m not sure what I’m missing. Sorry if I’m asking a dumb question :confused:

The .Prev and .Next methods on .Page are static, based on Hugo’s default sort order.

The .Prev and .Next methods on .Pages are based on the page collection that you define. For example:

{{ $p := where site.RegularPages "Type" "posts" }}
{{ with $p.ByDate.Reverse.Prev . }}
  <a href="{{ .RelPermalink }}">Prev</a>
{{ end }}
1 Like

That explains a lot, appreciate it big time sir!

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