The Events Calendar - Upcoming Events Shortcode


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. function upcoming_events_shortcode($atts){
  2.  
  3. extract( shortcode_atts( array(
  4. 'limit' => 5,
  5. ), $atts ) );
  6.  
  7. $upcoming_events = tribe_get_events(array('posts_per_page'=>$limit, 'eventDisplay'=>'upcoming') );
  8.  
  9. $i=0;
  10. $result='<div id="event-box"><ul>';
  11.  
  12. foreach ( $upcoming_events as $post )
  13. {
  14. $sdate = date('n/j', strtotime( tribe_get_start_date($post->ID, true, 'm/j') ) );
  15. $stime = tribe_get_start_date( $post->ID, false, 'g:i a' );
  16. $etime = tribe_get_end_date( $post->ID, false, 'g:i a' );
  17.  
  18. $result .= '<li><h4><a class="blacklink" href="' . get_permalink($post->ID) . '">';
  19. if( $stime == '12:00 am' ){
  20. $result .= $sdate; //all day event
  21. }else if( $stime != $etime ){
  22. $result .= $sdate . ' <span class="time">@ ' . $stime . ' - ' . $etime . '</span>';
  23. }else{
  24. $result .= $sdate . ' <span class="time">@ ' . $stime . '</span>';
  25. }
  26.  
  27. $result .= '</a></h4><p>';
  28. $title = $post->post_title;
  29. $result .= substr($title, 0, 65);
  30. if (strlen($title) > 65) $result .= " ...";
  31. $result .= '</p>';
  32.  
  33. if( ($i%$limit) == 0 && $i>0) { $result .= '</li>'; }
  34. $i++;
  35. }//end foreach
  36. $result .= '</ul></div><!-- end #event-box -->';
  37. return $result;
  38. }
  39. add_shortcode( 'upcoming_events', 'upcoming_events_shortcode' );

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.