How to Count All Posts in Ghost

Sometimes you might want to do a custom feature inside your Ghost theme and you need the total number of posts in your blog.

You can do this by using get helper. Let's fetch all posts in the blog by setting limit="all". If you don't set a limit, the default one, 15, will be used. To show the total number of posts fetched use {{posts.length}}. Here is the full code:

{{#get "posts" limit="all"}}

You can also use {{}} to display the total number of posts. This code will only work on pages that accept pagination: index.hbs, author.hbs and tag.hbs.

You might want to count all posts with JavaScript:

$.get(ghost.url.api('posts', {limit: 'all'})).done(function (data){
    console.log('posts', data.posts.length);

That's all.

I want more

Are you interested in a specific Ghost issue, feature or tutorial and we didn't cover it up in our blog? Drop us a message and we might write about it.