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.

One channel entry per category

April 23, 2012 6:35pm

Subscribe [3]
  • #1 / Apr 23, 2012 6:35pm

    James L

    40 posts

    Hello all,

    Does anyone know a way to show one entry per category in a channel:entries tag or a custom query? This has to be dynamic to show only the single latest entry from each category, and not all entries have categories.

    Any help appreciated. Thanks.

    EDIT: There’s also another thread, which means I’m working around this idea for now unless anyone has anything.

  • #2 / Apr 27, 2012 11:22am

    Man With A Peg

    124 posts

    Hey James,

    At the moment EE is tied to MySQL, which may allow you to get away with some MySQL-specificness:

    SELECT ct.entry_id, ct.title, c.cat_name
    FROM exp_categories c
    LEFT JOIN exp_category_posts cp ON (cp.cat_id = c.cat_id)
    LEFT JOIN exp_channel_titles ct ON (ct.entry_id = cp.entry_id)
    GROUP BY c.cat_id
    ORDER BY ct.entry_date DESC

    This would probably have a different effect on other SQL engines, but MySQL appears to choose its GROUP BY values according to ORDER BY.

    EDIT: 100 posts. W00t! Now I can annoy people on the User Guide too. ^_^

  • #3 / Apr 28, 2012 6:34am

    raafal537

    2 posts

    Thankjs it helped me

  • #4 / Apr 28, 2012 11:23am

    Man With A Peg

    124 posts

    [removed]

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

ExpressionEngine News!

#eecms, #events, #releases