Question regarding Next Prev navigation

From what I’ve seen at the Hugo Docs repository the next and the previous url paths are specified on the front matter of each post. For example:

---
next: /extras/builders
prev: /taxonomies/ordering
title: Aliases
weight: 10
---

Is this the only way to do this? Or is there some other way to get this functionality without specifying the url paths on every post?

There are many ways two rome.

  • .Next, .Prev
  • .NextInSection, .PrevInSection
  • And @spf13’s undocumented new feature

An undocumented feature? Care to elaborate? Is this implemented on a website that I can look at?

I’m thinking about migrating my drawing blog to hugo and since I have some 350 posts entering those path urls manually seems like overkill.

The first two options is documented. Use the search on the doc site.

The last one I believe is undocumented, but if you read Go code, see this commit:

Theres also

Thanks for your pointers bjornerik.

I found that the following code does what I need.
I’m posting it here just in case someone else needs it. It goes in single.html

{{ if .PrevInSection }}
<a href="{{.PrevInSection.Permalink}}">Previous Post</a>
{{ end }}
{{ if .NextInSection }}
<a href="{{.NextInSection.Permalink}}">Next Post</a>
{{ end }}
3 Likes