event list group by date

This topic contains 6 replies, has 2 voices, and was last updated by  Stephen Harris 10 years, 2 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #14062

    hi,
    when using eo_events and using a range of dates, say from 23-30/12/2014, is there a way to display them grouped by date?
    something like this:
    23/12/2014
    * 12:00 – item 1
    * 13:00 – item 2
    24/12/2014
    * 10:00 – item 4
    * 16:00 – item 5

    instead of:
    23/12/2014 12:00 – item 1
    23/12/2014 13:00 – item 2
    24/12/2014 10:00 – item 4
    24/12/2014 16:00 – item 5

    thanks !

    Rachel

    Rachel Druskin
    #14077

    Hi Rachel,

    Yes there is. Todo this you would need to edit the template shortcode-event-list.php (copy it to your theme and edit it there). I’ll leave the details to you but, the following handles the logic of ensuring events are grouped together correctly:

    First, at the top of the template, set $current_date = false;. This keeps track of the current date ‘group’ we are in. Below I’m grouping by date, but this could easily be adapted to by month or year.

    The logic is fairly simple. If the current event has the same date as $current_date, then we add the event to that group. If it is not, we end that group and start a new one. The resulting HTML is something like:

    <h3> {date} </h3>
    <ul> 
    <li> {event} </li>
    <li> {event} </li>
    </ul>
    
    <h3> {date} </h3>

    Here’s the snippet below which should go inside the while loop. (You’ll probably want to remove the existing <ul> & </ul> tags from the template.

    if( $current_date != eo_get_the_start('Ymd') ){
    
        if( $current_date ){
            //End previous group
            echo '</ul>';
        }
    
        //Start new group
        echo '<h3>'.eo_get_the_start('jS F Y').'</h3>';
        echo '<ul>';
    
        $current_date = eo_get_the_start('Ymd');
    
    }
    Stephen Harris
    #14078
    Stephen Harris
    #14086

    thank you Stephen!

    Rachel Druskin
    #14100

    hi Stephen,
    i copied the file to template dir with the changes you sent, but i dont see it affect the post 🙁

    Rachel Druskin
    #14101

    another thing – how can i combine this with Placeholder Tags?
    say i’m using this to display events from Dec 13 to the 24 and having myTag
    [eo_events event_start_after=”2014-12-16″ event_end_before=”2014-12-24″ event_tag=”myTag”]%start{ H:i}%: %event_title% ב%event_venue% (%event_cats%)[/eo_events]

    thanks!

    Rachel Druskin
    #14120

    Hi Rachel,

    If you’re using the placeholders, the template is ignored, so that would explain why it is not having any affect. Unfortunately you combine the two, but you can adapt the template further.

    The equivalent of

    %start{ H:i}%: %event_title% ב%event_venue% (%event_cats%)

    would be

    <?php
     printf( 
         "%s: %s ב %s (%s)",
         eo_get_the_Start( "H:i" ),
         get_the_title(),
         eo_get_venue_name(),
         get_the_term_list( get_the_ID(), 'event-category', '', ', ','')
    );
    ?>
    Stephen Harris
Viewing 7 posts - 1 through 7 (of 7 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.