Okay
  Public Ticket #2197519
Custom Template for Events Displaying
Closed

Comments

  • ssis-apps started the conversation

    Hi!


    How can I use WordPress Actions for creating Custom Template for Events Displaying?

    I need something like Grid View only with slider functionality.

    I need to display these fields:

    1. Event name (I take it from the post title)
    2. Event Date
    3. Event Location
    4. Event Time

    Also how can I display in custom template repeated events?

    Thank you!

  •  894
    Zhivko replied

    Hi,

    Here's how you can obtain events for given date range.

    First place this function in your theme functions.php file:

    function stec_get_events_between($start, $end, $tz = 'UTC') {
        $range_start = new \DateTime($start, new \DateTimeZone($tz));
        $range_end   = new \DateTime($end, new \DateTimeZone($tz));
        $events                 = \Stachethemes\Stec\Events::get_events();
        $processed_events_array = array();
        foreach ($events as $event) {
            if ($event->get_rrule() !== '') {
                $occurencies = $event->get_occurrences($range_start->format('Y-m-d'), $range_end->format('Y-m-d'));
                foreach ($occurencies as $k => $occurence) {
                    if ($occurence['repeat_offset'] === 0 && $k === 0) {
                        continue;
                    }
                    $r_event = clone $event;
                    $r_event->set_start_date($r_event->get_start_date('Y-m-d H:i:s', $occurence['repeat_offset']));
                    $r_event->set_end_date($r_event->get_end_date('Y-m-d H:i:s', $occurence['repeat_offset']));
                    if ($r_event->get_start_date('U') < $range_start->format('U') || $r_event->get_end_date('U') > $range_end->format('U')) {
                        continue;
                    }
                    $processed_events_array[] = $r_event;
                }
            } else {
                if ($event->get_start_date('U') < $range_start->format('U') || $event->get_end_date('U') > $range_end->format('U')) {
                    continue;
                }
                $processed_events_array[] = $event;
            }
        }
        usort($processed_events_array, function($a, $b) {
            return $a->get_start_date('U') > $b->get_start_date('U') ? 1 : -1;
        });
        return $processed_events_array;
    }
    

    This function obtains all events from the calendar, processes the repeat rules, compares the start and end ranges, sorts the events by dates and returns array with events.


    You can use this functions in your custom template page like following:

    $events = stec_get_events_between('2019-01-01', '2019-12-31');
    foreach ($events as $event) {
        echo "<p>{$event->get_title()}</p>";
        echo "<p>{$event->get_start_date('d M Y H:i:s')}</p>";
        $location_data = $event->get_parsed_location();
        if ($location_data) {
            echo "<p>{$location_data->full_address}</p>";
        }
        echo '<hr>';
    }
    


    Stachethemes Developer

  • ssis-apps replied

    Great!

    This is what I need!

    Thank you!

  • ssis-apps replied

    Hi!

    I use  for date range this combination (I want to display only upcoming events):

    $events_start = date('m/d/Y');
    $events_end = date('Y-m-d', strtotime($date. ' + 30 days'));
    $theme_path = get_stylesheet_directory_uri();
    $events = stec_get_events_between($events_start, $events_end);

    and get this error:

    Invalid UNTIL property: The value of the UNTIL rule part MUST be a date if DTSTART is a date.

    I think it is related with events on current date. 

    Can you help?

    Thanks.



  •  894
    Zhivko replied

    Hi,

    Is it possible to send me ics file of your events?


    Stachethemes Developer