When using {exp:channel:categories} to list categories, is it possible to sort the list by the number of entries each category has associated with it?


I'd make use of GWcode Categories which is an excellent free addon where you can simple do something like this:

{exp:gwcode_categories entry_count="yes" orderby="entry_count" sort="desc"}

    {cat_name} ({entry_count})


Where in this example I'm ordering by the entry count (descending) and also outputting the entry count if desired.


You can try this sql with Query module:

{exp:query sql="SELECT count(exp_category_posts.entry_id) AS total_entries, exp_categories.cat_id, exp_categories.cat_name, exp_categories.cat_url_title 
FROM exp_category_posts 
LEFT JOIN exp_categories ON exp_categories.cat_id=exp_category_posts.cat_id 
WHERE exp_categories.group_id=1 
GROUP BY cat_id 
ORDER BY count(entry_id) DESC"}

Total Number of entries = {total_entries}, Category ID = {cat_id}, Category Name = {cat_name}, Category URL Title = {cat_url_title}
<br />&nbsp;<br />


You need to update the category group id in WHERE condition (group_id=1) and ORDER BY either DESC or ASC.

With the above query, you can get other info like total number entries in a particular category, category name, category id and category url title.

I hope, it would help you.

  • Thanks for your answer @Bhashkar. I've gone with the GWcode Categories which seems a little simpler. Apr 15 '13 at 19:00
  • @Sam, I looked at this plugin and it seems much simpler :) . Apr 15 '13 at 19:11

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.