如何在 Hugo 中按类别过滤帖子

Ary*_*mar 2 hugo

如何按类别分类法过滤 Hugo 中的帖子 我有三个主要类别,如网络、Linux 和网络,我想显示该类别最近的 3 篇帖子。请有人告诉我该怎么做。

Joo*_*stS 6

最后 3 个帖子来自 3 个类别

{{ $p := where site.RegularPages "Type" "posts" }}
{{ $p = where $p "Params.categories" "intersect" (slice "web" "Linux" "networking" }}

{{ range first 3 $p }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
Run Code Online (Sandbox Code Playgroud)

来源:https ://discourse.gohugo.io/t/list-down-posts-from-multiple-categories/36701

1 个类别的最后 3 个帖子

{{ $p := where site.RegularPages "Type" "posts" }}
{{ $p = where $p "Params.categories" "intersect" (slice "web") }}

{{ range first 3 $p }}
  <h2><a href="{{ .RelPermalink }}">{{ .Title }}</a></h2>
{{ end }}
Run Code Online (Sandbox Code Playgroud)

来源:https ://discourse.gohugo.io/t/show-posts-by-category-not-working/33690