Files
blog/layouts/partials/func/count_posts.html
T
2022-02-20 20:00:01 +01:00

26 lines
665 B
HTML

<!-- Function to count number of posts for a given tag name -->
<!-- Example: Count posts with tag="ddo" -->
<!-- len={ { partial "count_posts.html" ( dict "context" $PageContext "term" "ddo" ) } } -->
{{$term := .term}}
{{$taxo := "tags"}}
{{ $ret := -1 }}
<!-- Get all posts-->
{{ $posts := where .context.Site.Pages "Type" "posts" }}
{{ $data := newScratch }}
<!-- (re)set the counter to 0 -->
{{ $data.Set "tagCounter" 0 }}
<!-- increment counter if post contains the current tag-->
{{ range $posts}}
{{ if in .Params.tags $term }}
{{ $data.Add "tagCounter" 1 }}
{{ end }}
{{ end }}
{{ $ret = $data.Get "tagCounter" }}
{{ return $ret }}