I have modified the code from this question but I'm running into an issue.
{% set allCats = craft.categories.group('blogCategories').level(1).find() %}
{% set catArray = {} %}
{% for cat in allCats %}
{% set catArray = catArray | merge({(cat.id):craft.entries.relatedTo(cat).total() }) %}
{% endfor %}
{% set catArray = catArray|sort|reverse %}
{% for catId, count in catArray %}
{% set category = craft.categories.id(catId).first() %}
<li>
<a href="{{ category.url }}">{{ category.title }} <span>{{count}}</span></a>
</li>
{% endfor %}
Ive ran a dump on the catArray array and the category id isnt being set as the key, regardless of if I try put brackets around it to protect it, I only get the value in the array.
cat.id
in brackets? Actually no reason to do this..category.slug
as a key, butcategory.id
does not want to work.