Advertisement
BakerMan

Today's Events (2.0.11) Widget - based on Jonah's random ver

Mar 5th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.42 KB | None | 0 0
  1. /*
  2. Plugin Name: The Events Calendar: Today's Events Widget
  3. Description: This widget will display all of today's events, if there are any.
  4.     Based on Jonah/Tim's code for the Tribe Random Events Widget.
  5.     Targets The Events Calendar 2.0.11.
  6. Version: 1.0
  7. Author: jonahcoyote, barryhughes
  8. Author URI: http://tri.be?ref=tec-plugin
  9. Text Domain: tribe-widget-todays-event
  10. License: GPLv2 or later
  11. */
  12.  
  13. add_action( 'widgets_init', create_function( '', "register_widget( 'Tribe_Widget_Todays_Event' );" ) );
  14.  
  15. class Tribe_Widget_Todays_Event extends WP_Widget {
  16.  
  17.     function __construct() {
  18.         $widget_ops = array(
  19.             'classname'   => 'widget_todays_events',
  20.             'description' => __( "Displays today's events (if any exist).", 'tribe-widget-todays-event' )
  21.         );
  22.         parent::__construct( 'widget_todays_events', __( "Today's Event Widget", 'tribe-widget-todays-event' ), $widget_ops );
  23.         add_action( 'tribe_widget_todays_event_display', array( $this, 'event_display' ), 10, 1 );
  24.     }
  25.  
  26.     function form( $instance ) {
  27.         // setup defaults or saved values
  28.         $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : __('todays Event','tribe-widget-todays-event');
  29.  
  30.         ?>
  31.         <p>
  32.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'tribe-widget-todays-event' ); ?>
  33.                 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
  34.             </label>
  35.         </p>
  36.     <?php
  37.     }
  38.  
  39.     function update( $new_instance, $old_instance ) {
  40.         $instance = $old_instance;
  41.         $instance['title'] = strip_tags( $new_instance['title'] );
  42.         return $instance;
  43.     }
  44.  
  45.     function widget( $args, $instance ) {
  46.         extract($args);
  47.         $title  = $instance['title'];
  48.  
  49.         // setup todays query args
  50.         $args = array(
  51.             'post_type'      => array(TribeEvents::POSTTYPE), // use post_type IN () to avoid old tribe queries
  52.             'posts_per_page' => 1000,
  53.             'post_status'    => 'publish',
  54.             'meta_query'     => array(
  55.                 array(
  56.                     'key'     => '_EventStartDate',
  57.                     'value'   => array(
  58.                         date('Y-m-d', strtotime('now')).' 00:00:00',
  59.                         date('Y-m-d', strtotime('now')).' 23:59:59'),
  60.                     'compare' => 'BETWEEN',
  61.                     'type'    => 'DATETIME'
  62.                 )
  63.             )
  64.         );
  65.  
  66.         $event = new WP_Query( $args );
  67.         wp_reset_query();
  68.  
  69.         // if no event is found exit gracefully
  70.         if( empty($event->posts) )
  71.             return apply_filters('tribe_widget_todays_event_none_found', null);
  72.  
  73.         echo $before_widget;
  74.  
  75.         if ( $title )
  76.             echo $before_title . $title . $after_title;
  77.  
  78.         do_action('tribe_widget_todays_event_display', $event);
  79.  
  80.         echo $after_widget;
  81.     }
  82.  
  83.     function event_display( $event ) {
  84.         while ( $event->have_posts() ) : $event->the_post();
  85.             ?>
  86.             <h5 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h5>
  87.             <div class="entry-date">
  88.                 <span class="start"><?php echo tribe_get_start_date(); ?></span>
  89.                 <?php if(tribe_is_multiday( get_the_ID() ) || tribe_get_all_day( get_the_ID() ) ) : ?>
  90.                     <span class="divider"> - </span>
  91.                     <span class="end"><?php echo tribe_get_end_date(); ?></span>
  92.                 <?php endif; ?>
  93.             </div>
  94.             <div class="entry-content">
  95.                 <?php
  96.  
  97.                 if (has_excerpt())
  98.                     the_excerpt();
  99.                 else
  100.                     the_content();
  101.  
  102.                 ?>
  103.                 <a href="<?php the_permalink(); ?>" class="read-more">View Details &raquo;</a>
  104.             </div>
  105.         <?php
  106.         endwhile;
  107.     }
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement