2

I feel like there's an obvious answer to this, but is it possible to have one channel entries tag with multiple channels and group the output by channel? For example:

{exp:channel:entries
    channel="blog|news|press_releases"
    dynamic="no"
    limit="50"
    orderby="channel"
}
    {!-- All Blog Entries First --}

    {!-- All News Entries Second --}

    {!-- All Press Releases Entries Third --}
{/exp:channel:entries}
  • Please, help me to understand. Why not to use three exp:channel:entries? – Robson Sobral May 18 '13 at 0:52
  • It looks like she wants to limit the entries to the 50 most recent between these channels. Separating would make that count hard to achieve dynamically. – Stephen Callender May 19 '13 at 8:05
6

Textbook use case for Stash:

{exp:channel:entries
    channel="blog|news|press_releases"
    dynamic="no"
    limit="50"
}
  {exp:stash:append_list name="entries" context="{channel_short_name}"}
    {stash:url_title}{url_title}{/stash:url_title}
    {stash:title}{title}{/stash:title}
  {/exp:stash:append_list}
{/exp:channel:entries}

<ul>
{exp:stash:get_list name="entries" context="blog" process="end"}
  <li><a href="{path='blog/{url_title}'}">{title}</a></li>
{/exp:stash:get_list}

{exp:stash:get_list name="entries" context="news" process="end"}
  <li><a href="{path='news/{url_title}'}">{title}</a></li>
{/exp:stash:get_list}

{exp:stash:get_list name="entries" context="press_releases" process="end"}
  <li><a href="{path='press_releases/{url_title}'}">{title}</a></li>
{/exp:stash:get_list}
</ul>
  • I'd always look to go this route with Stash too. – Ian May 19 '13 at 16:19
  • I tried setting it up just like this, and the template debugger shows the Stash variables being created, but no entries are being returned between the get_list tags. I'm a Stash n00b, so I don't really know how to troubleshoot. Suggestions? – kmgdev May 20 '13 at 16:14
  • For process="end" to work you need to be using the latest Stash (2.3.6), EE 2.4 or later and have the Stash extension installed. – Mark Croxton May 20 '13 at 21:44
  • Also, you should use {exp:stash:append_list} to capture the entry data since the Stash tags are nested inside the channel entries tag pair rather than wrapped around it. – Mark Croxton May 20 '13 at 21:47
  • OK, I edited Rob's code above as I spotted a mismatched tagpair too. – Mark Croxton May 20 '13 at 21:53
0

Something like,

{if channel_id=="Blog Entries ID #"} Content {/if}
{if channel_id==" News Entries ID #"} Content {/if}

etc. etc?

I do believe that the order of the conditionals top to bottom will output which you want to go first, next, etc.

  • I'm pretty sure that would still output the entries by date. I'd use something like that if I needed to output different code per-channel (like I wanted blog entries to be red, and news entries to be green). So what that's saying is "if the entry you're about to output is in the blog channel, use this code". – kmgdev May 17 '13 at 22:42
0

To achieve it, you can use a small query to get the channel name and passing one by one in channel entry tag like:

{exp:query sql="SELECT channel_name FROM exp_channels WHERE channel_name IN ('blog', 'news', 'press_releases') ORDER BY FIELD(channel_name,'blog', 'news', 'press_releases')"}

{exp:channel:entries
    channel="{channel_name}"
    dynamic="no"
    limit="50"
    orderby="channel"
}

###### entries ########

{/exp:channel:entries}

{/exp:query}

I hope, it would help you.

Not the answer you're looking for? Browse other questions tagged or ask your own question.