• Hi. I’m trying to display one event at the top of my main blog page….and I can’t seem to get the event to display at all. Instead, it’s just displaying the first post of the blog twice, but without content.

    Here is my code:

    <?php $events = eo_get_events(array(
           'numberposts'=>1,
           'event_start_after'=>'today',
           'showpastevents'=>true,//Will be deprecated, but set it to true to play it safe.
      )); ?>
    
    <?php if($events): ?>
    
    	<article class="post">
    		<a href="<?php the_permalink();?>"><?php if ( has_post_thumbnail() ) { echo get_the_post_thumbnail($page->ID, 'medium', array('class' => 'post-thumbnail')); } ?></a><?php $key = 'Video'; $themeta = get_post_meta($post->ID, $key, TRUE); if($themeta != '') { echo get_post_meta($post->ID, 'Video', true); } ?>
    		<a href="<?php the_permalink();?>"><h2><?php the_title(); ?></h2></a>
    
    		<div class="entry-content">
    
    			<div class="entry-meta">
    
    				When: <?php eo_get_next_occurrence('F jS, Y'); ?><br/>
    				Where: <a href="/vetro/directions/"><?php $current_events_venue_id = eo_get_venue(); ?></a>
    
    			<?php the_content(); ?>
    
    		</div><!-- .entry-content -->
    
    	</article><!-- #post-<?php the_ID(); ?> -->
    
    <?php endif; ?>
    
    			<?php global $post; // required
    			$args = array('category' => -10);
    			?>
    			<?php if (have_posts()): ?>
    			<?php while(have_posts()) : the_post(); ?>
    
    				<article class="post">
    					<a href="<?php the_permalink();?>"><?php if ( has_post_thumbnail() ) { echo get_the_post_thumbnail($page->ID, 'medium', array('class' => 'post-thumbnail')); } ?></a><?php $key = 'Video'; $themeta = get_post_meta($post->ID, $key, TRUE); if($themeta != '') { echo get_post_meta($post->ID, 'Video', true); } ?>
    					<a href="<?php the_permalink();?>"><h2><?php the_title(); ?></h2></a>
    					<div class="meta">Posted <span class="entry-date"><?php the_time('m.d.y') ?></span><span class="meta-sep"> by <?php the_author_posts_link(); ?></span> | <a href="<?php comments_link(); ?>">Leave a Comment</a></div><!--meta-->
    					<?php the_content( 'Read more ?' ); ?>
    					<div class="clearfix"></div>
    				</article><!--post-->
    
    			<?php endwhile; ?>
    			<?php endif; ?>

    Any ideas what I’m doing wrong?

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Stephen Harris

    (@stephenharris)

    For the top part you are not in ‘The Loop’, so you will need to pass the event ID and occurrence ID arguments.

    Also $events is an array, so you’ll want to do a foreach on that. Event ID is $event->ID and occurrence ID is $event->occurrence_id inside that foreach-loop.

    Thread Starter iamharlan

    (@iamharlan)

    Thanks for the reply! I might need a bit of help working through that. Is there an example of this being worked through somewhere? I’m not the best php coder…so I’m kind of just reverse engineering this thing.

    Thread Starter iamharlan

    (@iamharlan)

    Ok…I have this almost working completely…with one small issue remaining. I would like the content of the event to show with it in the display. It currently is just stripping the < ? php the_content ?> tag out. Any ideas?

    Here’s the code:

    <article class="post blog-event">
    
    		<?php $event_args = array(
    		    'numberposts' => 1,
    		    '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): ?>
    
    		<a href="<?php the_permalink();?>"><?php if ( has_post_thumbnail() ) { echo get_the_post_thumbnail($page->ID, 'medium', array('class' => 'post-thumbnail')); } ?></a><?php $key = 'Video'; $themeta = get_post_meta($post->ID, $key, TRUE); if($themeta != '') { echo get_post_meta($post->ID, 'Video', true); } ?>
    		<a href="<?php the_permalink();?>"><h2><?php the_title(); ?></h2></a>
    
    		<div class="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 Vetro 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><!-- meta -->
    
    		<?php the_content( 'Read more ?' ); ?>		
    
    		<div class="clearfix"></div>			
    
    			<?php    endforeach;  
    
    			    //Reset post variable
    		    $post = $temp;
    			endif; ?>
    
    	</article><!--blog-event-->
    Plugin Author Stephen Harris

    (@stephenharris)

    Do you meant its stripping out tags from the post content? Not sure why it would do that.

    Though you cannot use the_oontent() outside of the loop. See: https://stephenharris.info/get-post-content-by-id/

    Thread Starter iamharlan

    (@iamharlan)

    I am just getting back around to this, and I’m still having trouble. I understand the idea of getting the content by an ID, but as this is being pulled dynamically, i.e. the latest event, I can’t really just do that can I?

    Basically I just want to place the event, or a list of events on the page, and have it pull the content from the event as well as everything else. Everything is working correctly, except the content. It’s just blank there.

    Any ideas?

    Plugin Author Stephen Harris

    (@stephenharris)

    Did you look at https://stephenharris.info/get-post-content-by-id/? Just setting up the global $post, is not enough for the_content(). The above tutorial shows you how to get round that.

    Just pass $post->ID to the function in the tutorial to get the content outside the loop.

    Thread Starter iamharlan

    (@iamharlan)

    Yeah, I guess this is just over my head. Like I said, I’m not much of a php coder. Placing the code from the post above in my content is just causing errors on the page.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Problems with adding an event in addition to main loop…’ is closed to new replies.