HUGO

Showing recent posts inside a single without showing the post you're seeing

I want to show the 3 most recent posts at the bottom of a post. I’m using first and where but I don’t know if there’s a way to don’t display the post you’re reading on the list.
I just found an after 1 type of filtering a loop.

Any idea if that is possible?

1 Like

You can do something like this … Maybe

{{ range first 3 .Site.RegularPages }}
{{ if ne . $. }}

{{ end }}
{{ end }}

You risk getting only 2 pages somewhere …

That said, I will think you’d be happier with

You’re right, related content would be better for the reader. Didn’t know it was possible.
Thanks.

I don’t know why is not working.
I copied and pasted the example in the docs:

{{ $related := .Site.RegularPages.Related . | first 5 }}
{{ with $related }}

<h3>See Also</h3>
<ul>
{{ range . }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{ end }}
</ul>
{{ end }}

and on my config

[related]
threshold = 80
includeNewer = true
toLower = false
[[related.indices]]
name  = "tags"
weight = 100
[[related.indices]]
name  = "categories"
weight = 140

I also tried nachocaru solution and nothing.

Which Hugo version are you using? In which template have you inserted the Related content snippet?

v0.24.1

In the blog/single.html template

Related Content was introduced in Hugo 0.27. You need to update your Hugo version.

2 Likes

Done!
thank you so much, I completely ignore my version.