Displaying the post count for each tag

#1

I’m trying to display the number of posts for each tag on a Blog Collection page. e.g.

  • Alpha Tag (2 posts)
  • Bravo Tag (4 posts)
  • Charlie Tag (3 posts)

Here is the code I tried…

{{#get "tags" limit="6"}}
  {{#foreach tags }}
    {{name}}
    {{plural ../pagination.total empty='posts' singular='% post' plural='% posts'}}
  {{/foreach}}
{{/get}}

I only get the total number of posts for the blog, not the tag. I assume the pagination helper doesn’t work in this context. Is there another way to get the post count?

Thanks!

#2

Hi @fling. You can try using “include” parameter with “count.posts” value to get post count for each of the tags like described in Ghost docs here:

Cheers!

#3

That worked perfectly. Thanks!

Followup question – is it possible to sort a list of tags by count (or anything)? The sort of items seems arbitrary.

#4

You can sort as followed.

{{#get 'tags' limit='all' include='count.posts' order='count.posts desc'}}