Hi,
I’m trying to output the number of posts in a category as described in the Collection documentation.
I am using the blueprints from the demo theme.
In Blog\Post added
categories:
type: entries
source: Blog\Category
in Blog\Category added
posts:
type: entries
source: Blog\Post
inverse: categories
hidden: true
made Save&Migrate
in patrial right_block.htm
3 collections added to patrial right_block.htm
- blog - Blog\Post
- blogCategories - Blog\Category
- blogConfig - Blog
And I’m trying to display the number of posts in each category.
{% set cat = blogCategories.withCount('posts').get() %}
{% set cat = blogCategories.withCount('posts'.get(}}
{% for category in blogCategories %}
<li class="{{ activeBlogCategory == category.slug ? 'active' }}">
<a href="{{ 'blog/category'|page({ slug: category.slug, id: category.id }) }}">
{{ category.title }} {{ cat }}
</a>
</li><br/>
{% endfor %}
Returns a list of categories, but it doesn’t contain the number of posts.
What am I doing wrong?