Related Content Default

In the Related Content documentation it says, “List related content: To list up to 5 related pages (which share the same date or keyword parameters) is as simple as including something similar to this partial in your single page template”

However, I am finding that both snippets below only list related if other content date comes before the current page. So “My First Post” actually has no related content.

<!-- snippet 1 -->
 {{ $page := . }}
  {{ $opts := dict
    "indices" (slice "tags" "keywords")
    "document" $page
  }}

  {{ $related := .Site.RegularPages.Related $opts | first 5 }} {{ with $related }}
  <h3>See Also</h3>
  <ul>
    {{ range . }}
    <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
    {{ end }}
  </ul>
  {{ end }}
<!-- snippet 2-->
  {{ $related2 := .Site.RegularPages.Related . | first 5 }}
  {{ with $related2 }}
  <h3>See Also</h3>
  <ul>
  {{ range . }}
  <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
  {{ end }}
  </ul>
  {{ end }}

My intention is to list related content by keywords only for now. I assume user error, what am I missing? Thanks.

Edit: hugo v0.125.1

[related]
  includeNewer = true
1 Like

If you add a related configuration section, you need to add a complete configuration. It is not possible to just set, say, includeNewer and use the rest from the Hugo defaults.

[related]
  includeNewer = true
  threshold = 80
  toLower = false
  [[related.indices]]
    applyFilter = false
    cardinalityThreshold = 0
    name = 'keywords'
    pattern = ''
    toLower = false
    type = 'basic'
    weight = 100
  [[related.indices]]
    applyFilter = false
    cardinalityThreshold = 0
    name = 'date'
    pattern = ''
    toLower = false
    type = 'basic'
    weight = 10
  [[related.indices]]
    applyFilter = false
    cardinalityThreshold = 0
    name = 'tags'
    pattern = ''
    toLower = false
    type = 'basic'
    weight = 80

Follow up, this only seems to work in the hugo.toml but not the theme.toml. Is this intentional?

Yes. The theme.toml file contains meta data about the theme, primarily for the Hugo Themes site. It has nothing to do with site configuration.

1 Like

OK sounds good, thanks for the info. As a user my thought process was “I am developing a theme, my layouts are in the theme folder, my layouts use related pages, therefore this functionality could be related to the theme config”