【问题标题】: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 }}
  <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
{{ end }}

【问题讨论】:

    标签: go hugo hugo-content-organization


    【解决方案1】:

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

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

    {{ range (where .CurrentSection.Pages "Permalink" "ne" .Permalink) }}
        <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
    {{ end }}
    

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2019-01-29
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-18
    相关资源
    最近更新 更多