WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] Conditional template tags (7 posts)

  1. David Hunt
    Member
    Posted 1 year ago #

    Hi,

    Instead of using formats within the plugin settings, I want to create custom single-event.php, single-location.php, etc. for my theme. I've almost got them working but I'm not sure how to replicate the conditional placeholders with template tags.

    This is the template code right now:

    <article <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <?php $ID = get_the_ID(); ?>
    	<dl>
    		<dt><?php _e('Date/Time', 'themename'); ?></dt>
    		<?php em_events( array( 'post_id' => $ID, 'format_header' => '<dd>', 'format' => '#_EVENTDATES — <i>#_EVENTTIMES</i>', 'format_footer' => '</dd>') ); ?>
    
    		{has_location}
    		<dt><?php _e('Location', 'themename'); ?></dt>
    		<?php em_events( array( 'post_id' => $ID, 'format_header' => '<dd>', 'format' => '#_LOCATIONLINK', 'format_footer' => '</dd>') ); ?>
    		{/has_location}
    
    		<dt><?php _e('Category(ies)', 'themename'); ?></dt>
    		<?php em_events( array( 'post_id' => $ID, 'format_header' => '<dd>', 'format' => '#_CATEGORIES', 'format_footer' => '</dd>') ); ?>
    	</dl>
    
    	<?php em_events( array( 'post_id' => $ID, 'format_header' => '<div class="entry">', 'format' => '#_EVENTNOTES', 'format_footer' => '</div>') ); ?>
    
    	{has_bookings}
    	<h3><?php _e('Bookings', 'themename'); ?></h3>
    	<?php em_events( array( 'post_id' => $ID, 'format_header' => '', 'format' => '#_BOOKINGFORM', 'format_footer' => '') ); ?>
    	{/has_bookings}
    
    	{has_location}
    	<?php em_events( array( 'post_id' => $ID, 'format_header' => '<div class="eventMap">', 'format' => '#_MAP', 'format_footer' => '</div>') ); ?>
    	{/has_location}
    
    	<?php wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number')); ?>
    </article>

    What do I need to replace {has_location}, {has_bookings} etc. with in order to make those sections conditional?

    Also, are there any issues with the multiple calls of em_events()?

    Cheers,

    David

    http://wordpress.org/extend/plugins/events-manager/

  2. Daedalon
    Member
    Posted 1 year ago #

    Subscribing for replies.

  3. agelonwl
    Member
    Posted 1 year ago #

    hi,

    you can do something like

    echo EM_Events::output( array( 'limit'=>1,'format'=>'{has_location}<div><h2>Location</h2>#_LOCATIONNAME</div>{/has_location}') );
  4. David Hunt
    Member
    Posted 1 year ago #

    Thanks for the reply, agelonwl. But I'm not sure that is an ideal solution, because I don't think I can wrap the text strings in _e() or __(), can I?

  5. David Hunt
    Member
    Posted 1 year ago #

    I've been working on this a bit more. Does anyone see a problem with this solution?

    <article <?php post_class() ?> id="post-<?php the_ID(); ?>">
    	<div class="entry">
    	<?php $ID = get_the_ID();
    	// First call EM_Events::get() using this post's ID,
    	// to store all the info about this single event
    	$evts = EM_Events::get( array( 'post_id' => $ID ) );
    
    	// then use a combination of em_events() and conditional statements
    	// (on the object $evt contained in the array $evts) where necessary
    	foreach ($evts as $evt) : ?>
    		<dl>
    			<dt><?php _e('Date/Time', 'themename'); ?></dt>
    			<?php em_events( array( 'post_id' => $ID, 'format_header' => '<dd>', 'format' => '#_EVENTDATES — <i>#_EVENTTIMES</i>', 'format_footer' => '</dd>') ); ?>
    
    			<?php if ($evt->location_id) : ?>
    			<dt><?php _e('Location', 'themename'); ?></dt>
    			<dd><?php em_events( array( 'post_id' => $ID, 'format_header' => '<dd>', 'format' => '{has_location}#_LOCATIONLINK{/has_location}', 'format_footer' => '</dd>') )?></dd>
    			<?php endif; ?>
    		</dl>
    
    		<?php em_events( array( 'post_id' => $ID, 'format_header' => '', 'format' => '#_EVENTNOTES', 'format_footer' => '') ); ?>
    
    		<?php if ($evt->event_rsvp) : ?>
    				<h3><?php _e('Bookings', 'themename'); ?></h3>
    				<?php em_events( array( 'post_id' => $ID, 'format_header' => '', 'format' => '#_BOOKINGFORM', 'format_footer' => '') );
    		endif; ?>
    
    		<?php if ($evt->location_id) em_events( array( 'post_id' => $ID, 'format_header' => '<div class="eventMap">', 'format' => '#_MAP', 'format_footer' => '</div>') ); ?>
    
    		<?php wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number')); ?>
    	<?php endforeach; ?>
    	</div>
    </article>
  6. agelonwl
    Member
    Posted 1 year ago #

  7. David Hunt
    Member
    Posted 1 year ago #

    Aha, thanks agelonwl. Using that post, I was able to refine my code to avoid repeatedly calling em_events():

    <article <?php post_class() ?> id="post-<?php the_ID(); ?>">
    	<div class="entry">
    	<?php $ID = get_the_ID();
    	$evt = em_get_events( array( 'post_id' => $ID ) );
    
    	<dl>
    		<dt><?php _e('Date/Time', 'themename'); ?></dt>
    		<?php echo $evt->output('#_EVENTDATES — <i>#_EVENTTIMES</i>'); ?>
    
    		<?php if ($evt->location_id) : ?>
    		<dt><?php _e('Location', 'themename'); ?></dt>
    		<dd><?php echo $evt->output('#_LOCATIONLINK'); ?></dd>
    		<?php endif; ?>
    	</dl>

    etc...

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic