I would like to create a Next link on all pages that point to the next page having the same tag. The default Next points to the next entry chronologically. I would like to filter out entries that are not related tag-wise. The code .Site.RegularPages.Related . | first 3 gives me the previous related 3 entries. How do I get the next ones instead?
Thanks a lot for your follow-up. It’s very appreciated. However, if includeNewer = true is used then .Site.RegularPages.Related . | first 3 will give me top 3 most recent (absolute), not the next 1 more recent. In a way, I am looking for an alternate of .Site.RegularPages.Related where the inequality comparison with .Date is inverted. Is there any way to implement this using the Hugo syntax?
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 }}