ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How can I display a count of entries in a category?

August 18, 2011 8:15am

Subscribe [3]
  • #1 / Aug 18, 2011 8:15am

    I’ve tried using {count} and {total_results} but these only show the ID of the category or something like that, not what I expected.

    Is there an easy was to get the number of entries found for each category so that I can have something like:

    CategoryA (x results)
    CategoryB (x results)
    etc

  • #2 / Aug 18, 2011 8:33am

    Mark Bowen

    12637 posts

    Take a look at the excellent plugins over on GWCode.com, more specifically :

    http://gwcode.com/add-ons/gwcode-categories/examples/example4

    These are really fantastic plugins and allow you to do loads with categories. I personally believe they should be bundled as standard with ExpressionEngine.

    Hope that helps a bit.

    Best wishes,

    Mark

  • #3 / Aug 18, 2011 11:47am

    I ended up sorting with with a simple SQL query, I think it was the most efficient way in the end although I do wish I didn’t have to hard code queries.

    {exp:query sql="SELECT count(*) as entry_count FROM exp_category_posts WHERE cat_id = '{category_id}' "}
        {entry_count}
    {/exp:query
  • #4 / Aug 18, 2011 12:04pm

    Boyink!

    5011 posts

    I’ve seen a few add-ons over the years to do that - did you check devot-ee?

  • #5 / Aug 18, 2011 1:06pm

    Mark Bowen

    12637 posts

    I ended up sorting with with a simple SQL query, I think it was the most efficient way in the end although I do wish I didn’t have to hard code queries.

    Well if you use the add-on I linked to above then you don’t need to worry any more 😉

    I’ve seen a few add-ons over the years to do that - did you check devot-ee?

    As above.

  • #6 / Aug 18, 2011 8:07pm

    I did check out those Add-ons, thanks, but I can’t bring myself to bloat the install with yet another plug-in for a single trivial feature either.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases