Restruction
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
|
||||
<!-- 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 }}
|
||||
Reference in New Issue
Block a user