Support

Home Forums Event Espresso Premium How do I display the time

How do I display the time

Posted: June 2, 2021 at 8:43 am

Viewing 7 reply threads


dhi001

June 2, 2021 at 8:43 am

This is Josh’s plugin.

I am using the https://github.com/eventespresso/ee-code-snippet-library/blob/master/shortcodes/jf_other_site_event_list.php plugin

I dont know php but there are some changes I need to make
I am trying to edit the code to display the date and time next to each other. This is the code for the date

function my_rest_api_event_list( $atts ) {
    $atts = shortcode_atts( array(
        'url' => ''
    ), $atts, 'other_site_event_list' );
    $curdate_utc = date("Y-m-d H:i:s");
    if($atts['url'] == '') {
        return;
    }
    $data_url = esc_url($atts['url']) . "/wp-json/ee/v4.8.36/events?calculate=image_medium_large&include=Datetime&where[Datetime.DTT_EVT_start][]=>&where[Datetime.DTT_EVT_start][]=" . urlencode($curdate_utc);
    $json = file_get_contents($data_url, true); 
    $events = json_decode($json, true); 
    $count = count( $events ); 
    $html = '<div id="embedded-events" style="max-width: 700px; margin: 0 auto;">';
	$counter = 1;
    if ($count > 0){
        foreach ($events as $event){
            $html .= '<div class="embedded-event">';
            $html .= '<h3><a href="' . $event[ 'link' ] . '">' . $event[ 'EVT_name' ] . '</a></h3>';
			/*
			$html .= '<div style="text-align:center">';
            $featured_image_url = $event['_calculated_fields']['image_medium_large']['url'];
            $html .= $featured_image_url ? '<a href="' . esc_url( $event['link'] ). '"><img src="' . esc_url( $featured_image_url ) . '" /></a>' : '';
            $html .= '</div>'; 
			*/
            $html .= '<ul>';
            $i = 0;
            foreach( $event[ 'datetimes' ] as $datetime ) {
                $html .= '<li style="list-style:none">' . date( 'j F Y', strtotime( $event[ 'datetimes' ][ $i ][ 'DTT_EVT_start' ] ) ).'</li>';
                $i++;
            }
            $html .= '</ul>';
			/*
            $html .= '<p>' . wp_trim_words($event[ 'EVT_desc' ]['rendered'], 55) . '&nbsp;<a href="' . $event[ 'link' ] . '">Learn more</a></p>';
			*/
            $html .= '</div><hr />';
			if ($counter++ == 3) break;
        }
    }
    $html .= '</div>';
    return $html;
}

I am not sure how I separate it out for the time of the event so it displays next to the date.

I am also trying to order by date as all the events come out jumbled. Any help would be appreciate.

Thanks in advance
Andrea


Tony

  • Support Staff

June 2, 2021 at 9:25 am

Hi Andrea,

That snippet is intended to allow you to output a list of events from another site other than the one you are using that shortcode on, so before moving forward, are you using this on the same site that Event Espresso is installed on or another?

What format are you wanting to use for the time? Date and time?


dhi001

June 2, 2021 at 9:37 am

I am using on a totally different site from the site which has EE installed. The plugin works fine. I made a few modifications and those work fine.

The layout of the date and time should be like this (one under the other)
24 June 2021
12:30 – 14:00

I have the date sorted but not the time. This is how it is displayed on our other site.


Tony

  • Support Staff

June 2, 2021 at 2:36 pm

I am using on a totally different site from the site which has EE installed. The plugin works fine. I made a few modifications and those work fine.

OK, I was checking as you mentioned you don’t know PHP so you may have not been familiar with that function using the REST API, which is usually used to access the data from another site. Adding an event list on the same site can be don using the EE Model System and we often see users using something like the above rather than the models.

The layout of the date and time should be like this (one under the other)
24 June 2021
12:30 – 14:00

For that you’ll need something like this:

$html .= '<li style="list-style:none">';
$html .= date( 'j F Y', strtotime( $event[ 'datetimes' ][ $i ][ 'DTT_EVT_start' ] ) );
$html .= '<br>';
$html .= date( 'H:i', strtotime( $event[ 'datetimes' ][ $i ][ 'DTT_EVT_start' ] ) ) . ' - ' . date( 'H:i', strtotime( $event[ 'datetimes' ][ $i ][ 'DTT_EVT_end' ] ) );
$html .= '</li>';


dhi001

June 3, 2021 at 2:47 am

Thank you so much. As I look at the code it seems so simple but when you don’t know, you don’t know. One last thing please, is how do I order the events list as it currently pulls events randomly and I would like the latest events first.
Thank you again
Andrea


Tony

  • Support Staff

June 3, 2021 at 4:33 am

They are ordered by the ID by default, so you’ll need to set an order_by parameter on the REST API request, info here:

https://github.com/eventespresso/event-espresso-core/blob/master/docs/C–REST-API/ee4-rest-api-GET-filtering-results.md#order_by

For example:

$data_url = esc_url($atts['url']) . "/wp-json/ee/v4.8.36/events?calculate=image_medium_large&include=Datetime&where[Datetime.DTT_EVT_start][]=>&where[Datetime.DTT_EVT_start][]=" . urlencode($curdate_utc) . "&order_by=Datetime.DTT_EVT_start";


dhi001

June 4, 2021 at 5:29 am

Thanks. I will try this out.
Thank you


Tony

  • Support Staff

June 4, 2021 at 6:43 am

You’re most welcome.

Viewing 7 reply threads

The support post ‘How do I display the time’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso