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.

I need to create a category list with total of entries

June 27, 2007 2:51am

Subscribe [1]
  • #1 / Jun 27, 2007 2:51am

    ummedia

    466 posts

    Please Is this possible in EE

    I would like to create a list of categories like this

    PAINTING
    LANDSCAPE(23)
    ABSTRACT(5)
    PORTRAIT(3)
    DRAWING
    ETCHING(6)
    PEN AND INK(7)
    SCULPTURE
    BRONZE(5)
    CONTEMPORARY(3)


    Painting, Drawing and Sculpture are all Category Groups, everything with a total is a category. I would like to return all categories from their respective category group with a total of of entries per category. It would be nice if any category without an entry would not be listed.

    many thanks in advance regards Adam

  • #2 / Jun 27, 2007 12:51pm

    Robin Sowell

    13255 posts

    The wiki has an entry on getting category counts- but it won’t pull up categories with no entries.  You could try…

    SELECT count(exp_category_posts.entry_id) AS post_count,
    exp_category_posts.cat_id, exp_categories.cat_name
    FROM exp_categories LEFT JOIN exp_category_posts ON exp_categories.cat_id = exp_category_posts.cat_id, exp_weblog_titles
    WHERE exp_category_posts.cat_id = exp_categories.cat_id AND parent_id='0'
    AND exp_weblog_titles.weblog_id = '1'
    AND exp_weblog_titles.entry_id = exp_category_posts.entry_id
    GROUP BY exp_categories.cat_name

    Untested- but think it’s in the ball park.

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

ExpressionEngine News!

#eecms, #events, #releases