Return to Snippet

Revision: 65817
at January 23, 2014 04:20 by crypticsoft


Initial Code
function upcoming_events_shortcode($atts){

extract( shortcode_atts( array(
		'limit' => 5,
	), $atts ) );	

	$upcoming_events = tribe_get_events(array('posts_per_page'=>$limit, 'eventDisplay'=>'upcoming') );

	$i=0;
	$result='<div id="event-box"><ul>';

	foreach ( $upcoming_events as $post )
	{
		$sdate = date('n/j', strtotime( tribe_get_start_date($post->ID, true, 'm/j') ) );
		$stime = tribe_get_start_date( $post->ID, false, 'g:i a' );
		$etime = tribe_get_end_date( $post->ID, false, 'g:i a' );			

		$result .= '<li><h4><a class="blacklink" href="' . get_permalink($post->ID) . '">';
		if( $stime == '12:00 am' ){
			$result .= $sdate; //all day event
		}else if( $stime != $etime ){
			$result .= $sdate . ' <span class="time">@ ' . $stime . ' - ' . $etime . '</span>';
		}else{
			$result .= $sdate . ' <span class="time">@ ' . $stime . '</span>';
		}

		$result .= '</a></h4><p>';
		$title = $post->post_title;
		$result .= substr($title, 0, 65);
		if (strlen($title) > 65) $result .= " ...";
		$result .= '</p>';

		if( ($i%$limit) == 0 && $i>0) { $result .= '</li>'; }
		$i++;
	}//end foreach
	$result .= '</ul></div><!-- end #event-box -->';
	return $result;
}
add_shortcode( 'upcoming_events', 'upcoming_events_shortcode' );

Initial URL
http://wordpress.org/plugins/the-events-calendar/

Initial Description
This shortcode was tested with The Events Calendar version 3.3.1 
Usage: [upcoming_events limit="6"]

Initial Title
The Events Calendar - Upcoming Events Shortcode

Initial Tags
wordpress

Initial Language
PHP