在雨果的嵌套部分中的帖子范围

分享于2022年07月17日 go hugo hugo-content-organization 问答
【问题标题】:在雨果的嵌套部分中的帖子范围(Range over posts in nested section in hugo)
【发布时间】:2022-05-03 10:19:10
【问题描述】:

我使用此代码在 /content/posts 中的帖子的相同部分中显示相关帖子。但是,当我将内容移动到嵌套部分(例如 content/posts/news )时,代码停止工作,导致出现其他部分的内容。谁能提供解决方案或指导我如何完成这项工作?

{{ range where (where site.RegularPages "Section" .Section) "Permalink" "ne" .Permalink }}
  {{ .LinkTitle }}
{{ end }}


【解决方案1】:

尝试使用 .CurrentSection.Pages ,这比过滤来自 site.RegularPages 的所有结果更适合。

那么当前页面也可以通过简单的 where 语句过滤掉。

{{ range (where .CurrentSection.Pages "Permalink" "ne" .Permalink) }}
    {{ .LinkTitle }}
{{ end }}

  • 正如目前所写,您的答案尚不清楚。请 edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息 in the help center