4

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

Cheers

1 Answer 1

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, 2014 at 18:13
  • Wow, how'd I forget to change that? Fixed, thanks. Jun 22, 2014 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.