0

Given a category (not the category group), is there a way to get the count entries assigned to that category? I'm hoping for a native EE solution. This seems to suggest that there isn't one: Anyone know of a plugin to show Category count?. Can I do this in EE only?

  • If you have received the answer to your question please choose your desired answer. – mattsidjohn Jul 6 '14 at 2:26
2

Here is a plugin that will give you the desired result you need without a custom query.

http://devot-ee.com/add-ons/entries-number

| improve this answer | |
1

I think the simplest and quickest solution if no one wrote a plug-in already would be:

{exp:query sql="SELECT COUNT(entry_id) AS cat_count FROM exp_category_posts WHERE cat_id=1"}{cat_count}{/exp:query}

Note: Untested.

Obviously replace the cat_id value with the category ID you want to count entries for. :)

If you don't have the category ID in the URL, but have its category_url_title:

SELECT COUNT(entry_id) AS cat_count
FROM exp_category_posts AS cp
JOIN exp_categories AS c ON cp.cat_id = c.cat_id
WHERE c.cat_url_title = "{segment_X}"
| improve this answer | |

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.