Confused as to how related content works and how to make it work

Spent a few hours using search (Google and here) to get a handle on why using the techniques here for related posts aren’t working for Hugo Book theme. My guess is there is an implied bit I’m missing in the instructions.

Hugo version: v0.73.0-428907CC/extended linux/amd64
Theme: Hugo Book theme

My /layouts/posts/single.html

{{ define "main" }}
<article class="markdown">
  <h1>
    {{ .Title }}
  </h1>
{{ partial "docs/breadcrumbs.html" . }}
  {{ partial "docs/post-meta" . }}
  <p>
    {{- .Content -}}
  </p>{{- range .Params.authors }}
  {{- with $.Site.GetPage "taxonomyTerm" (printf "authors/%s" (urlize .)) }}
  <hr class="new4">
<div class="move">
      <img src="/imgs/me.png" alt=""/>
<h3>Written By <a href="https://www.matthartley.com/" target="_blank">Matt Hartley</a></h3>
{{ .Content }}
{{ with .Params.twitter }}
  <p>
    <a href="https://twitter.com/{{ substr . 1 }}">
      Follow {{ $.Params.name }} on Twitter
    </a></br></br><hr class="new4"></div>
  </p>
{{ end }}
  {{ end }}
{{ end }}
</article>
{{ $related := .Site.RegularPages.RelatedTo ( keyVals "Development")  ( keyVals "date" .Date ) }}
{{ end }}
{{ define "toc" }}
  {{ partial "docs/toc" . }}
{{ end }}

my /layouts/partials/docs/related.html

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

What I’m trying to accomplish:

  • I’d like to have related posts appear below the single blog post’s contents.
  • I’d like related posts to be based on either category or keyword.

Many thank you(s)

What does this mean?

What does your config.toml look like?

Does your content have any categories or keywords in front matter?

Please post a link to the public repository for your site. See:
https://discourse.gohugo.io/t/requesting-help/9132

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

Figured out an alternative. Thanks for the feedback, I’ll remember that next time.

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