• Resolved iamharlan

    (@iamharlan)


    Hi. I’m working with a static home page…and in one section, I would like to include the next upcoming event. I feel like this is probably a very easy fix using the “get events” function, but I seem to be doing something wrong. I’m usually very good at this, but alas.

    As I am developing for a client, it is difficult to share my link, apologies there. Just imagine you’re having to call the loop and create a section where just the next event comes up. I’d also like to be able to style the event with the thumbnail and title and date and such.

    Any help would be fantastic.

    https://www.ads-software.com/extend/plugins/event-organiser/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Something like this should work.

    <?php
    $event_args = array(
        'numberposts' => 1,
        'orderby' => 'eventstart',
        'order' => 'ASC',
        'showpastevents' => false,
        'post_status' => 'publish'
    );
    
    $events = eo_get_events($event_args);
    
    if ($events):
        $return= ''; 
    
        foreach ($events as $event):
            $return .= $event->post_title;
        endforeach;  
    
        echo $return;
    endif;
    ?>

    You might also just be able to use the available shortcode: Shortcode Documentation

    <?php echo do_shortcode("[eo_events]"); ?>

    Thread Starter iamharlan

    (@iamharlan)

    The shortcode listed out all of the events. Not exactly what I was wanting.

    However, the other option did get me started. It’s returning the post title only at the moment. How do I call the rest of the information? Like the date and time and the thumbnail, etc. I’m basically wanting everything I have on the single event page, with the exception of the content. Here’s what I have on that page…

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    	<?php echo get_the_post_thumbnail($id, 'large'); ?>
    
    	<h1 class="entry-title"><?php the_title(); ?></h1>
    
    	<div class="entry-meta">
    
    <!-- Choose a different date format depending on whether we want to include time -->
    
    <?php if(eo_is_all_day()): ?>
    	<!-- Event is all day -->
    		<?php $date_format = 'F jS, Y'; ?>
    <?php else: ?>
    	<!-- Event is not all day - include time in format -->
    		<?php $date_format = 'F jS, Y g:ia'; ?>
    <?php endif; ?>
    
    <?php printf(__('<h2>%s</h2>','eventorganiser'), eo_get_the_start($date_format) );?>
    
    <?php if(eo_reoccurs()):?>
    	<!-- Event reoccurs - is there a next occurrence? -->
    	<?php $next =   eo_get_next_occurrence($date_format);?>
    <?php if($next): ?>
    	<!-- If the event is occurring again in the future, display the date -->
    								<?php printf(__('This event is running from %1$s until %2$s. The next chance to catch it at Fred's is %3$s','eventorganiser'), eo_get_schedule_start('F jS, Y'), eo_get_schedule_last('F jS, Y'), $next);?>
    
    <?php else: ?>
    
    <!-- Otherwise the event has finished (no more occurrences) -->
    								<?php printf(__('This event finished on %s','eventorganiser'), eo_get_schedule_last('F d, Y',''));?>
    
    <?php endif; ?>
    
    <?php else: ?>
    
    <!-- Event is a single event -->
    
    <?php endif; ?>
    </div><!-- .entry-meta -->
    
    <!-- The content or the description of the event-->
    	<?php the_content(); ?>
    
    <?php endwhile; endif; ?>

    Daniel’s first answer should work – the default setting for the shortcode is to display all events. But you can use the showpastevents attribute and set it to false.

    That said – rather than using showpastevents I’d encourage you to use event_start_after or event_end_after and set it to ‘now’ (depending on whether you want to include ‘running’ events). I’ll eventually depreciate showpastevents as the arguments/attributes event_start_after,event_end_after, event_start_before, event_end_before all accept relative date formats. (These are available in eo_get_events() and has attributes in [eo_events]).

    Iamharian, here’s what I would do:

    $event_args = array(
        'numberposts' => 5,
        'orderby' => 'eventstart',
        'order' => 'ASC',
        'event_end_after' => 'today',
    );
    
    $events = eo_get_events($event_args);
    
    if ($events):
        $return= '';
        global $post;
        $temp = $post;
    
        foreach ($events as $post):
    
    	<?php echo get_the_post_thumbnail(get_the_ID(), 'large'); ?>
    
    	<h1 class="entry-title"><?php the_title(); ?></h1>
    
    	<div class="entry-meta">
            <!-- Choose a different date format depending on whether we want to include time -->
    
    	<?php if(eo_is_all_day()): ?>
    		<!-- Event is all day -->
    		<?php $date_format = 'F jS, Y'; ?>
    	<?php else: ?>
    		<!-- Event is not all day - include time in format -->
    		<?php $date_format = 'F jS, Y g:ia'; ?>
    	<?php endif; ?>
    
    	<?php printf(__('<h2>%s</h2>','eventorganiser'), eo_get_the_start($date_format) );?>
    
    	<?php if(eo_reoccurs()):?>
    		<!-- Event reoccurs - is there a next occurrence? -->
    		<?php $next =   eo_get_next_occurrence($date_format);?>
    		<?php if($next): ?>
    			<!-- If the event is occurring again in the future, display the date -->
    
    			<?php 	printf(__('This event is running from %1$s until %2$s. The next chance to catch it at Fred's is %3$s','eventorganiser'), eo_get_schedule_start('F jS, Y'), eo_get_schedule_last('F jS, Y'), $next);?>
    
    		<?php else: ?>
    
    			<!-- Otherwise the event has finished (no more occurrences) -->
    			<?php printf(__('This event finished on %s','eventorganiser'), eo_get_schedule_last('F d, Y',''));?>
    
    		<?php endif; ?>
    
    	<?php else: ?>
    
    	<!-- Event is a single event -->
    
    	<?php endif; ?>
    	</div><!-- .entry-meta -->
    
        endforeach;  
    
        //Reset post variable
        $post = $temp;
    endif;
    Thread Starter iamharlan

    (@iamharlan)

    That’s looking like something I want…but I’m getting T-string errors. I’m thinking I need to wrap some of it in php tags…but I’m not exactly where. Anywhere I wrap it…I get the same errors.

    Thread Starter iamharlan

    (@iamharlan)

    Nevermind. It was the apostrophe in the line about “Fred’s” It’s fixed. Thanks a ton guys!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Event Organiser] Displaying next upcoming event outside of the loop.’ is closed to new replies.