Add Events widget
This commit is contained in:
145
admin/widgets/events.php
Normal file
145
admin/widgets/events.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
class SportsPress_Widget_Events extends WP_Widget {
|
||||
|
||||
function __construct() {
|
||||
$widget_ops = array('classname' => 'widget_recent_entries widget_sp_events', 'description' => __( 'SportsPress widget.', 'sportspress' ) );
|
||||
parent::__construct('sp_events', __( 'Events', 'sportspress' ), $widget_ops);
|
||||
}
|
||||
|
||||
function widget( $args, $instance ) {
|
||||
extract($args);
|
||||
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
|
||||
$status = empty($instance['status']) ? null : $instance['status'];
|
||||
$league = empty($instance['league']) ? null : $instance['league'];
|
||||
$season = empty($instance['season']) ? null : $instance['season'];
|
||||
$venue = empty($instance['venue']) ? null : $instance['venue'];
|
||||
$team = empty($instance['team']) ? null : $instance['team'];
|
||||
$number = empty($instance['number']) ? get_option( 'posts_per_page' ) : $instance['number'];
|
||||
$args = array(
|
||||
'status' => $status,
|
||||
'league' => $league,
|
||||
'season' => $season,
|
||||
'venue' => $venue,
|
||||
'team' => $team,
|
||||
'number' => $number,
|
||||
);
|
||||
echo $before_widget;
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
echo '<div id="sp_events_wrap">';
|
||||
echo sportspress_events( $args );
|
||||
echo '</div>';
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
function update( $new_instance, $old_instance ) {
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
$instance['status'] = strip_tags($new_instance['status']);
|
||||
$instance['league'] = intval($new_instance['league']);
|
||||
$instance['season'] = intval($new_instance['season']);
|
||||
$instance['venue'] = intval($new_instance['venue']);
|
||||
$instance['team'] = intval($new_instance['team']);
|
||||
$instance['number'] = intval($new_instance['number']);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function form( $instance ) {
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'status' => '', 'league' => '', 'season' => '', 'venue' => '', 'team' => '', 'number' => 3 ) );
|
||||
$title = strip_tags($instance['title']);
|
||||
$status = strip_tags($instance['status']);
|
||||
$league = intval($instance['league']);
|
||||
$season = intval($instance['season']);
|
||||
$venue = intval($instance['venue']);
|
||||
$team = intval($instance['team']);
|
||||
$number = intval($instance['number']);
|
||||
?>
|
||||
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('status'); ?>"><?php _e( 'Status:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$options = array(
|
||||
'any' => __( 'Any', 'sportspress' ),
|
||||
'played' => __( 'Played', 'sportspress' ),
|
||||
'scheduled' => __( 'Scheduled', 'sportspress' ),
|
||||
);
|
||||
?>
|
||||
<select id="<?php echo $this->get_field_id('status'); ?>" name="<?php echo $this->get_field_name('status'); ?>" class="widefat">
|
||||
<?php foreach( $options as $key => $name ): ?>
|
||||
<option value="<?php echo $key; ?>" <?php selected ( $key, $status ); ?>><?php echo $name; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('league'); ?>"><?php _e( 'League:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_league',
|
||||
'name' => $this->get_field_name('league'),
|
||||
'id' => $this->get_field_id('league'),
|
||||
'selected' => $league,
|
||||
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ),
|
||||
'hide_empty' => 0,
|
||||
'values' => 'term_id',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
wp_dropdown_categories( $args );
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('season'); ?>"><?php _e( 'Season:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_season',
|
||||
'name' => $this->get_field_name('season'),
|
||||
'id' => $this->get_field_id('season'),
|
||||
'selected' => $season,
|
||||
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Seasons', 'sportspress' ) ),
|
||||
'hide_empty' => 0,
|
||||
'values' => 'term_id',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
wp_dropdown_categories( $args );
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('venue'); ?>"><?php _e( 'Venue:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'taxonomy' => 'sp_venue',
|
||||
'name' => $this->get_field_name('venue'),
|
||||
'id' => $this->get_field_id('venue'),
|
||||
'selected' => $venue,
|
||||
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Venues', 'sportspress' ) ),
|
||||
'hide_empty' => 0,
|
||||
'values' => 'term_id',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
wp_dropdown_categories( $args );
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('team'); ?>"><?php _e( 'Team:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'name' => $this->get_field_name('team'),
|
||||
'id' => $this->get_field_id('team'),
|
||||
'selected' => $team,
|
||||
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
|
||||
'values' => 'ID',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
if ( ! sportspress_dropdown_pages( $args ) ):
|
||||
sportspress_post_adder( 'sp_table' );
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php printf( __( 'Number of %s to show:', 'sportspress' ), __( 'events', 'sportspress' ) ); ?></label>
|
||||
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3"></p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
add_action( 'widgets_init', create_function( '', 'return register_widget( "SportsPress_Widget_Events" );' ) );
|
||||
@@ -3,7 +3,7 @@ class SportsPress_Widget_League_Table extends WP_Widget {
|
||||
|
||||
function __construct() {
|
||||
$widget_ops = array('classname' => 'widget_league_table widget_sp_league_table', 'description' => __( 'SportsPress widget.', 'sportspress' ) );
|
||||
parent::__construct('sp_table', __( 'League Table', 'sportspress', 'sportspress' ), $widget_ops);
|
||||
parent::__construct('sp_table', __( 'League Table', 'sportspress' ), $widget_ops);
|
||||
}
|
||||
|
||||
function widget( $args, $instance ) {
|
||||
@@ -35,17 +35,19 @@ class SportsPress_Widget_League_Table extends WP_Widget {
|
||||
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
|
||||
|
||||
<p>
|
||||
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php _e( 'League Table:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_table',
|
||||
'name' => $this->get_field_name('id'),
|
||||
'id' => $this->get_field_id('id'),
|
||||
'show_option_none' => __( '-- Select --', 'sportspress' ),
|
||||
'selected' => $id,
|
||||
'values' => 'ID',
|
||||
'class' => 'widefat',
|
||||
);
|
||||
sportspress_dropdown_pages( $args );
|
||||
if ( ! sportspress_dropdown_pages( $args ) ):
|
||||
sportspress_post_adder( 'sp_table' );
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
|
||||
Reference in New Issue
Block a user