4

How do I list all categories in use alphabetically? And how to get the total post count from each category?

Cheers

9

The relatedTo param will do the trick:

{% set entries = craft.entries.limit(null) %}
{% for category in craft.categories.relatedTo(entries).order('title asc') %}
    {% set entryCount = entries.relatedTo(category).total() %}
    {{ category }} ({{ entryCount }})
{% endfor %}
2
  • 2
    I think you want to change 'tag' to 'category' in your example. Otherwise your answer should be correct. Jun 22 '14 at 18:13
  • Wow, how'd I forget to change that? Fixed, thanks. Jun 22 '14 at 19:07

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .