Support

Home Forums Event Espresso Premium Simple event list on one page

Simple event list on one page

Posted: May 7, 2017 at 4:58 am

Viewing 6 reply threads


T R

May 7, 2017 at 4:58 am

Hi there, I’m trying to get one of my pages to display a super simple text list of upcoming events and came across this forum post, which looks perfect: https://gist.github.com/joshfeck/6e33532c37a123bbf532

However, just not sure how I can get this to show on one page only. I want to keep all my existing pages and templates, etc. But on one of the pages I want to show this list.

What method is the best to get this done?

Thanks for any help.


Josh

  • Support Staff

May 8, 2017 at 9:48 am

Hi there,

You can use the code from the example gist and put it into a custom page template. Then when you set up the page in the WordPress editor, you select that page template.

This guide will walk you through the process:

http://www.wpbeginner.com/wp-themes/how-to-create-a-custom-page-in-wordpress/


T R

May 8, 2017 at 10:17 pm

Gotcha, thank you, figured it out, thanks for the direction.


T R

May 8, 2017 at 10:47 pm

Sorry, one more thing, I tried to get the event date to go along with the event name, but can’t seem to figure out which hook or tag to use.

I tried these, but it just showed numbers:
$event->primary_datetime()
$event->first_datetime()

How can I get the date to show as well?

Thank you.


Tony

  • Support Staff

May 9, 2017 at 3:35 am

$event->primary_datetime()

Returns and EE_Datetime object so you need to use one its methods to output the date.

$primary_datetime = $event->primary_datetime();

//Output the start date
$primary_datetime->e_start_date();


T R

May 9, 2017 at 4:41 am

Thanks for the help, but I can’t for the life of me figure out where to put each of these (PHP is definitely not my strong suit). This is where I put them but definitely not right. Seems no matter where I put this I can’t get it to work: $primary_datetime = $event->primary_datetime();

This is what I have right now:

$where = array(
	'Datetime.DTT_EVT_end' => array( '>=', current_time( 'mysql' )),
	'status' => 'publish',
);

// run the query
if ( class_exists( 'EE_Registry' ) ) :
$events = EE_Registry::instance()->load_model( 'Event' )->get_all( array(
	$where,
	'limit' => 100,
	'order_by' => 'Datetime.DTT_EVT_start',
	'order' => 'ASC',
	'group_by' => 'EVT_ID'
));
// the loop

if ( ! empty( $events )) {
	$primary_datetime = $event->primary_datetime();
	echo '<ul>';
	foreach ( $events as $event ) {
		if ( $event instanceof EE_Event ) {
			echo '<li>';
			echo '<a href="' . get_permalink( $event->ID() ) . '">' . $primary_datetime->e_start_date() . ' / ' . $event->name() . '</a>';
			echo '</li>';
		}
	}
	echo '</ul>';
} 
endif;

Can you point out where I’m going wrong?

Thanks so much for the help thus far.


Tony

  • Support Staff

May 9, 2017 at 5:08 am

You don’t have an $event when you’re trying to use it, it needs to be within the foreach loop, and better yet within the instanceof EE_Event check and as your echoing out the link, you don’t need the e_ function as that just echos anyway.

Try this:


if ( ! empty( $events )) {
	echo '<ul>';
	foreach ( $events as $event ) {
		if ( $event instanceof EE_Event ) {
			$primary_datetime = $event->primary_datetime();
			echo '<li>';
			echo '<a href="' . get_permalink( $event->ID() ) . '">' . $primary_datetime->start_date() . ' / ' . $event->name() . '</a>';
			echo '</li>';
		}
	}
	echo '</ul>';
}

Note: I haven’t tested this.

Viewing 6 reply threads

The support post ‘Simple event list on one page’ 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