Ronalds Vilciņš

Show related content in Hugo

Hugo has a built-in related content feature. To list up to 3 related pages include this partial in your single page template. It will match up pages based on common tags and will show the three most likely.

Add sample code in layouts/partials/related.html.

{{ $related := .Site.RegularPages.Related . | first 3 }}
{{ with $related }}
<h3>See also</h3>
	{{ range . }}
	<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
	{{ end }}
{{ end }}

And then include this partial template in one of your default template that you want to show. For example you can show related content in your _default/single.html, so it appears on every blog post.

Hugo’s related content default configuration (config.yaml):

  includeNewer: false
  - name: keywords
    weight: 100
  - name: date
    weight: 10
  threshold: 80
  toLower: false