<p>The <a href="http://buildwithcraft.com/docs/relations#the-relatedTo-param"><code>relatedTo</code></a> param will do the trick:</p>

<pre><code>{% 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 %}
</code></pre>

CC BY-SA 3.0
2014-06-22T18:13:45.153Z
I think you want to change 'tag' to 'category' in your example. Otherwise your answer should be correct.
Bryan Redeagle
CC BY-SA 3.0
2014-06-22T19:07:27.537Z
Wow, how'd I forget to change that? Fixed, thanks.
Simon Kuran
CC BY-SA 3.0
2014-06-22T07:49:47.320Z
2014-06-22T19:12:06.483Z
2014-06-22T19:12:06.483Z
Simon Kuran
<p>How do I list all categories in use alphabetically? And how to get the total post count from each category? </p>

<p>Cheers﻿</p>

<entries><categories>
Listing categories alphabetically & total post count
# Listing categories alphabetically & total post count

(Asked by: username_0 on 2014-06-22)

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

Cheers﻿

**Tags:** entries, categories

---

## 1 answers

### Answer by username_1 on 2014-06-22. Score: 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 %}

> **Comments:**
> **username_2**: I think you want to change 'tag' to 'category' in your example. Otherwise your answer should be correct.  
> **username_1**: Wow, how'd I forget to change that? Fixed, thanks.  

---

