Search code examples
ghost

ghost blog : how to display the number of filtered posts?


I am trying to display the number of filtered posts ( Casper standard theme) using partial loops

# In my tag-spark.hbs
<main class="content" role="main">
    {{> "loop_sparks"}}
</main>

# In my loop_sparks.hbs
{{#get "tags" filter="tag: arts"  include="count.posts"}}
   <p>ARTS POSTS: {{count.posts}}</p>
{{/get}}

I don't get the count displayed .... as stated in the doc => https://themes.ghost.org/docs/get

A Resource may have additional related data that can be included to expand your collection. Base Resource data: Post Tag User The User and Tag resources can be expanded to include the post count for each resource. Include options for User and Tag: "count.posts"

where am I wrong ?


Solution

  • I don't understand why my first code doesn't run ... however I found another piece of code in the doc which is displaying correctly the posts count

    {{#get "tags" limit="all"  include="count.posts" order="count.posts desc" filter="name: arts"}}
        <ul>
          {{#foreach tags}}
              <li><a href="/tag/{{slug}}">{{name}}</a>: {{count.posts}}</li>
          {{/foreach}}
        </ul>
    {{/get}}
    

    does it mean I need the #foreach to display the value ??