Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Plugin Name: The Events Calendar: Today's Events Widget
- Description: This widget will display all of today's events, if there are any.
- Based on Jonah/Tim's code for the Tribe Random Events Widget.
- Targets The Events Calendar 2.0.11.
- Version: 1.0
- Author: jonahcoyote, barryhughes
- Author URI: http://tri.be?ref=tec-plugin
- Text Domain: tribe-widget-todays-event
- License: GPLv2 or later
- */
- add_action( 'widgets_init', create_function( '', "register_widget( 'Tribe_Widget_Todays_Event' );" ) );
- class Tribe_Widget_Todays_Event extends WP_Widget {
- function __construct() {
- $widget_ops = array(
- 'classname' => 'widget_todays_events',
- 'description' => __( "Displays today's events (if any exist).", 'tribe-widget-todays-event' )
- );
- parent::__construct( 'widget_todays_events', __( "Today's Event Widget", 'tribe-widget-todays-event' ), $widget_ops );
- add_action( 'tribe_widget_todays_event_display', array( $this, 'event_display' ), 10, 1 );
- }
- function form( $instance ) {
- // setup defaults or saved values
- $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : __('todays Event','tribe-widget-todays-event');
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'tribe-widget-todays-event' ); ?>
- <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; ?>" />
- </label>
- </p>
- <?php
- }
- function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- $instance['title'] = strip_tags( $new_instance['title'] );
- return $instance;
- }
- function widget( $args, $instance ) {
- extract($args);
- $title = $instance['title'];
- // setup todays query args
- $args = array(
- 'post_type' => array(TribeEvents::POSTTYPE), // use post_type IN () to avoid old tribe queries
- 'posts_per_page' => 1000,
- 'post_status' => 'publish',
- 'meta_query' => array(
- array(
- 'key' => '_EventStartDate',
- 'value' => array(
- date('Y-m-d', strtotime('now')).' 00:00:00',
- date('Y-m-d', strtotime('now')).' 23:59:59'),
- 'compare' => 'BETWEEN',
- 'type' => 'DATETIME'
- )
- )
- );
- $event = new WP_Query( $args );
- wp_reset_query();
- // if no event is found exit gracefully
- if( empty($event->posts) )
- return apply_filters('tribe_widget_todays_event_none_found', null);
- echo $before_widget;
- if ( $title )
- echo $before_title . $title . $after_title;
- do_action('tribe_widget_todays_event_display', $event);
- echo $after_widget;
- }
- function event_display( $event ) {
- while ( $event->have_posts() ) : $event->the_post();
- ?>
- <h5 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h5>
- <div class="entry-date">
- <span class="start"><?php echo tribe_get_start_date(); ?></span>
- <?php if(tribe_is_multiday( get_the_ID() ) || tribe_get_all_day( get_the_ID() ) ) : ?>
- <span class="divider"> - </span>
- <span class="end"><?php echo tribe_get_end_date(); ?></span>
- <?php endif; ?>
- </div>
- <div class="entry-content">
- <?php
- if (has_excerpt())
- the_excerpt();
- else
- the_content();
- ?>
- <a href="<?php the_permalink(); ?>" class="read-more">View Details »</a>
- </div>
- <?php
- endwhile;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement