【问题标题】:Filter Hugo Pagination by Custom Param按自定义参数过滤 Hugo 分页
【发布时间】:2021-10-08 10:48:22
【问题描述】:

更新

参考 Oleg Butuzov 回答我可以解决我的第一个问题:

{{ $paginator := .Paginate (where .Site.RegularPages ".Params.yt" ">" "") 1 }}

但我有一个新问题,它列出了内容文件夹 Hugo 上包含参数“yt”的所有帖子,然后我从 @bep 回复的官方 Hugo Discusion https://discourse.gohugo.io/t/complex-where-filter-using-and-or-not/5758/3 解决了我的问题。

这里..如何用两个条件过滤 HUGO:

{{ $paginator := .Paginate (where (where .Site.RegularPages ".Params.yt" ">" "") ".Params.type" "post") 1 }}

我更新并清除了这个问题,因为它真的很难找到关于这个雨果问题,我希望它也能解决你的问题.. thx :)

======= 原始问题 ======

如何过滤变量 $Paginator 的“where”以仅列出包含自定义参数“yt”的帖子?

{{ $paginator := .Paginate (where .Site.RegularPages "Type" "post") 2 }}
{{ range $paginator.Pages }}
   {{ .Params.yt }}
{{ end }}

{{ template "_internal/pagination.html" . }} 

我的 Hugo 模板结构:

内容/发布/ ---- post1.md ---- post2.md

主题/布局/post/gameplay.html

然后

post1.md

---
Title: Title 1
type: post
yt: ytchannelid
---

post2.md

---
Title: Tile 2
type: post
---

thanks before :)

【问题讨论】:

    标签: go templates pagination blogs hugo


    【解决方案1】:

    您可以结合使用.Params 和比较运算符。

    因此,例如,我想在项目页面上显示唯一带有分叉的项目。

    {{ define "content" }}
      {{ range first 6 (where .Paginator.Pages ".Params.Forks" ">" "") }}
        <div class="inner">
        <pre>[{{.Params.Forks}}]</pre>
        <hr>
        </div>
      {{ end }}
    {{ end }}
    
    • where 手册页上查看更多信息。

    【讨论】:

    • 谢谢这对我有用,但我添加了多个 Where 条件,所以这是我的最终编码:{{ $paginator := .Paginate (where (where .Site.RegularPages ".Params.yt" " >" "") ".Params.type" "post") 1 }} thx :)
    • 选择它作为答案,这样其他人就可以寻找类似主题的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 2018-06-14
    • 2015-07-14
    • 2014-11-05
    • 2011-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多