I use this code to show related posts in the same sections for posts in /content/posts
. However, the code stops working when I move the content to a nested section, such as content/posts/news
, resulting in content from other sections appearing. Could anyone provide a solution or guide me on how to make this work?
{{ range where (where site.RegularPages "Section" .Section) "Permalink" "ne" .Permalink }}
<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
{{ end }}
Try using
.CurrentSection.Pages
, which is better fit for this than filtering all the results fromsite.RegularPages
.Then the current page can also be filtered out with a simple
where
statement.