How to link the next page with the same tag?

The collection of related pages excludes the current page. If you want to use the .Next and .Prev page methods, you must (a) append the current page to the collection of related pages, and (b) explicitly sort the resulting collection.

{{ $r := .Site.RegularPages.Related . | append . }}
{{ $r = sort $r "Date" "desc" }}

{{ with ($r.Prev .) }}
  <a href="{{ .RelPermalink }}">Previous Related Page</a>
{{ end }}

{{ with ($r.Next .) }}
  <a href="{{ .RelPermalink }}">Next Related Page</a>
{{ end }}

This is better.

3 Likes