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.

Can I get 3 entries and group by author?

April 24, 2012 2:27am

Subscribe [4]
  • #1 / Apr 24, 2012 2:27am

    esset

    191 posts

    I have a channel with 20 entries from 10 different authors. Now I want to get the latest 3 entries, but from 3 different authors. So let’s say I have these as my 5 latest entries:

    Entry ID | Author ID | Title
    1 | 1 | Some entry title 1
    2 | 4 | Some entry title 2
    3 | 4 | Some entry title 3
    4 | 5 | Some entry title 4
    5 | 6 | Some entry title 5

    When I now do a channel:entries limit=“3” I want these entries back:

    1 | 1 | Some entry title 1
    3 | 4 | Some entry title 3
    4 | 5 | Some entry title 4

    Is this possible?

    Thank you

  • #2 / Apr 24, 2012 6:52am

    Design by Front

    106 posts

    I guess this might be possible (though a little inefficient) using a series of embeds. So your main template would have:

    <ul>
    {!-- Get the latest entry --}
    {exp:channel:entries channel="news" limit="1"}
    <li>{title}</li>
    {embed=shared/_second_entry author_id="{author_id}"}
    {/exp:channel:entries}
    </ul>

    Then in your “shared/_second_entry” template:

    {!-- Get the latest entry, but exclude the author_id of the first result --}
    {exp:channel:entries channel="news" limit="1" author_id="not {embed:author_id}"}
    <li>{title}</li>
    {embed=shared/_third_entry author_id="{author_id}|{embed:author_id}"}
    {/exp:channel:entries}

    And finally in your “shared/_third_entry” template:

    {!-- Get the latest entry, but exclude the author_id of the first and second results --}
    {exp:channel:entries channel="news" limit="1" author_id="not {embed:author_id}"}
    <li>{title}</li>
    {/exp:channel:entries}

    Does this make sense? I haven’t tested it i’m afraid!
    Chuck

  • #3 / Apr 24, 2012 7:04am

    esset

    191 posts

    Nesting 3 templates? No way josé 😊

    Thanks for the input though. I’ll go with a custom query if needed but I was hoping there might be some build in way to achieve this through the channel:entries loop.

    Any one else that can think of something?

    Thanks

  • #4 / Apr 24, 2012 10:41am

    Barrel

    92 posts

    Maybe you could try using Snippets?  Can’t think of the solution off the top of my head, but maybe worth looking into http://ellislab.com/expressionengine/user-guide/templates/globals/snippets.html

  • #5 / Apr 24, 2012 10:58am

    esset

    191 posts

    Don’t see how snippets would solve my problem. But thanks anyways 😊

    This is more a selection problem with channel:entries.

  • #6 / Apr 25, 2012 10:27am

    Shane Eckert

    7174 posts

    Hi esset,

    Thank you for posting your question here on the ExpressionEngine forums.

    This is a pretty cool question. I thought about this for a bit, hoping something like order by would help here. I cannot think of a way to get all this in the same template. I like the idea that Front has and tried to make that happen in one template but it got messy.

    I think you may just need to use the Query Module and write up a nice little SQL statement.

    I hope this helps.

    Cheers,

  • #7 / Apr 25, 2012 10:30am

    esset

    191 posts

    Hi Shane

    Yeah, I went down the road and just made a GROUP BY custom query from the database. Would be a nice addition to the channel:entries tag though. Let the gods/geeks know 😊~

  • #8 / Apr 26, 2012 3:18pm

    Shane Eckert

    7174 posts

    Hey esset,

    Nice solution.

    I will let the Devs know. 😊

    If you need anything else, please just let us know by opening a new thread.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases