How do I list all categories in use alphabetically? And how to get the total post count from each category?
Cheers
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityHow do I list all categories in use alphabetically? And how to get the total post count from each category?
Cheers
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 %}