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.

List and group entries from a single expression?

November 16, 2011 5:29am

Subscribe [2]
  • #1 / Nov 16, 2011 5:29am

    stevealfa

    11 posts

    I’m wondering is it possible to run an expression that will list all of my entries from a certain channel and group them according to the data from a certain field:

    {exp:channel:entries channel='events' search:evnt_date="Saturday|Sunday|Monday"}
    <div class="event">
      <h2>{evnt_date}</h2>
    <p>  {exp:channel:entries channel='events' search:evnt_date="Saturday|Sunday|Monday"}<br />
      </p><h3>{title}</h3>
    <p>  {evnt_info}...<br />
      {/exp:channel:entries}<br />
    </div><!-- /.event --><br />
    {/exp:channel:entries}

    I know that the pipe doesn’t work in this case (or the code atall), it’s just to help try explain what I’d like to be happening.

    I’m using date as a custom field because the ‘events’ are only happening over a set amount days so this won’t need to change once it is set (saves scrolling through months of the calender for every entry)

    Currently this is how I’d run this page:

    <h2>Saturday</h2>
    <p>{exp:channel:entries channel='events' search:evnt_date="Saturday"}<br />
      </p><h3>{title}</h3>
    <p>  {evnt_info}...<br />
    {/exp:channel:entries}</p>
    
    <h2>Sunday</h2>
    <p>{exp:channel:entries channel='events' search:evnt_date="Sunday"}<br />
      </p><h3>{title}</h3>
    <p>  {evnt_info}...<br />
    {/exp:channel:entries}</p>
    
    <h2>Monday</h2>
    <p>{exp:channel:entries channel='events' search:evnt_date="Monday"}<br />
      </p><h3>{title}</h3>
    <p>  {evnt_info}...<br />
    {/exp:channel:entries}</p>
    
    <p><br />
    etc…

    ...because it is only the entries that would need to be dynamic here, but to keep this scalable I’d like to be able to run this a simpler way.

    I’m just thinking there must be a better, more efficient way to display this information.
    If categories are required that could also be an option, I haven’t been able to figure this one out.

    Thanks

  • #2 / Nov 16, 2011 5:42am

    Cheif

    626 posts

  • #3 / Nov 16, 2011 5:49am

    stevealfa

    11 posts

    Thanks for the suggestion, I had tried this but because my fields are custom it sorts alphabetically which unfortunately doesn’t work in this case.

    But also I need to group these with the day Title

    <h2>Day</h2>

    added before the entries that are listed within this day, otherwise I get the Day title above every entry, which is also not what I’m looking for.

    Thanks though.

  • #4 / Nov 17, 2011 3:37am

    John Henry Donovan

    12339 posts

    Hi Steve,

    Channel Entries has a Date Heading variable pair that can used in conjunction with the entry date

    Other than than the way you are doing it using multiple channel entries tags is one way to do it but highly inefficient

    Have you looked into the Calendar Module from Solspace?

  • #5 / Nov 17, 2011 5:07am

    stevealfa

    11 posts

    Thanks John, will this work with a custom date field? or does it require the date to be set in the date tab on the publish page. I also have got the calender module for this project so I will take a look at that.

    ...But Is this method not possible in a similar scenario with a custom field, for example if I wanted to list a lot of courses and have groupings of courses depending on what subject area they belonged to determined from the data in a custom field?:

    Maths:
    Course 1
    Course 2
    
    Science:
    Course 1
    Course 2
    Course 3
    
    History
    Course 1
    etc…

    could categories be used for this type of grouping?

    Thanks.

     

  • #6 / Nov 21, 2011 6:43am

    stevealfa

    11 posts

    I’ve not been able to figure this one out.
    I need to be able to run a more complex array than the standard channel entries tag will do.

    this is what I’m looking to do

    {exp:channel:entries channel='events'}
    <h2>{event_genre} [1]</h2>
    <p>{exp:channel:entries channel='events' search:evnt_date="Saturday"}<br />
      </p><h3>{title}</h3>
    <p>  {evnt_info}...<br />
    {/exp:channel:entries}</p>
    
    <h2>{event_genre} [2]</h2>
    <p>{exp:channel:entries channel='events' search:evnt_date="Sunday"}<br />
      </p><h3>{title}</h3>
    <p>  {evnt_info}...<br />
    {/exp:channel:entries}</p>
    
    <h2>{event_genre} [3]</h2>
    <p>{exp:channel:entries channel='events' search:evnt_date="Monday"}<br />
      </p><h3>{title}</h3>
    <p>  {evnt_info}...<br />
    {/exp:channel:entries}</p>
    
    <p>{/exp:channel:entries}

    If this page needs to list events by 20 (or more) {event_genre}‘s it starts to become unwieldy.

    I’m looking for a way to find all entries with matching {event_genre}‘s, group, list and find the next lot that match etc etc…

    Is there a more efficient way?

    Thanks

     

  • #7 / Nov 21, 2011 3:38pm

    Robin Sowell

    13255 posts

    As John Henry notes, there really isn’t a native way to do that using custom fields.

    The best native option would be setting the entry date as the event date and then using the date heading tag.

    Categories might also work- as long as the Category Archive tag will display everything you need.

    Non-native, I’ve done headings using php and writing a custom plugin to handle the heading bit wouldn’t be hard- as long as they’re in order, it’s a matter of comparing a value each loop- if the value changes, show it.  Otherwise, hide it.  But I’m not sure how easy it would be to get them in order.  (Using a date field would do it- but that is not w/out localization concerns.)

    I’ve also handled some sorting issues using reverse relationships- ‘Sunday’ is an entry, and then select ‘sunday’ as a related entry- show sunday and all its reverse related.  That has pros/cons as well.  Just depends on the overall needs whether it might work- and can be a bit clunky depending on the situation.

    This might be a better fit in ‘Community Help’ where you could brainstorm some options.  Natively there isn’t a tag or some such that does exactly what I think you want to do.  But there are a variety of ways it could be approached, depending on the circumstances.

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

ExpressionEngine News!

#eecms, #events, #releases