Add league table widget team limit
This commit is contained in:
@@ -8,6 +8,7 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
|
|||||||
$options = get_option( 'sportspress' );
|
$options = get_option( 'sportspress' );
|
||||||
|
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
|
'number' => -1,
|
||||||
'columns' => null,
|
'columns' => null,
|
||||||
'show_full_table_link' => false,
|
'show_full_table_link' => false,
|
||||||
'show_team_logo' => sportspress_array_value( $options, 'league_table_show_team_logo', false ),
|
'show_team_logo' => sportspress_array_value( $options, 'league_table_show_team_logo', false ),
|
||||||
@@ -39,6 +40,9 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
|
|||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
|
if ( is_int( $r['number'] ) && $r['number'] > 0 )
|
||||||
|
$data = array_slice( $data, 0, $r['number'] );
|
||||||
|
|
||||||
foreach( $data as $team_id => $row ):
|
foreach( $data as $team_id => $row ):
|
||||||
|
|
||||||
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class SportsPress_Widget_League_Table extends WP_Widget {
|
|||||||
extract($args);
|
extract($args);
|
||||||
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
|
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
|
||||||
$id = empty($instance['id']) ? null : $instance['id'];
|
$id = empty($instance['id']) ? null : $instance['id'];
|
||||||
|
$number = empty($instance['number']) ? null : $instance['number'];
|
||||||
$columns = empty($instance['columns']) ? null : $instance['columns'];
|
$columns = empty($instance['columns']) ? null : $instance['columns'];
|
||||||
$show_team_logo = empty($instance['show_team_logo']) ? false : $instance['show_team_logo'];
|
$show_team_logo = empty($instance['show_team_logo']) ? false : $instance['show_team_logo'];
|
||||||
$show_full_table_link = empty($instance['show_full_table_link']) ? false : $instance['show_full_table_link'];
|
$show_full_table_link = empty($instance['show_full_table_link']) ? false : $instance['show_full_table_link'];
|
||||||
@@ -17,7 +18,7 @@ class SportsPress_Widget_League_Table extends WP_Widget {
|
|||||||
if ( $title )
|
if ( $title )
|
||||||
echo $before_title . $title . $after_title;
|
echo $before_title . $title . $after_title;
|
||||||
echo '<div id="sp_league_table_wrap">';
|
echo '<div id="sp_league_table_wrap">';
|
||||||
echo sportspress_league_table( $id, array( 'columns' => $columns, 'show_full_table_link' => $show_full_table_link, 'show_team_logo' => $show_team_logo ) );
|
echo sportspress_league_table( $id, array( 'number' => $number, 'columns' => $columns, 'show_full_table_link' => $show_full_table_link, 'show_team_logo' => $show_team_logo ) );
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
echo $after_widget;
|
echo $after_widget;
|
||||||
}
|
}
|
||||||
@@ -26,6 +27,7 @@ class SportsPress_Widget_League_Table extends WP_Widget {
|
|||||||
$instance = $old_instance;
|
$instance = $old_instance;
|
||||||
$instance['title'] = strip_tags($new_instance['title']);
|
$instance['title'] = strip_tags($new_instance['title']);
|
||||||
$instance['id'] = intval($new_instance['id']);
|
$instance['id'] = intval($new_instance['id']);
|
||||||
|
$instance['number'] = intval($new_instance['number']);
|
||||||
$instance['columns'] = (array)$new_instance['columns'];
|
$instance['columns'] = (array)$new_instance['columns'];
|
||||||
$instance['show_team_logo'] = $new_instance['show_team_logo'];
|
$instance['show_team_logo'] = $new_instance['show_team_logo'];
|
||||||
$instance['show_full_table_link'] = $new_instance['show_full_table_link'];
|
$instance['show_full_table_link'] = $new_instance['show_full_table_link'];
|
||||||
@@ -34,9 +36,10 @@ class SportsPress_Widget_League_Table extends WP_Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function form( $instance ) {
|
function form( $instance ) {
|
||||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'columns' => null, 'show_team_logo' => false, 'show_full_table_link' => true ) );
|
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'number' => 5, 'columns' => null, 'show_team_logo' => false, 'show_full_table_link' => true ) );
|
||||||
$title = strip_tags($instance['title']);
|
$title = strip_tags($instance['title']);
|
||||||
$id = intval($instance['id']);
|
$id = intval($instance['id']);
|
||||||
|
$number = intval($instance['number']);
|
||||||
$columns = $instance['columns'];
|
$columns = $instance['columns'];
|
||||||
$show_team_logo = $instance['show_team_logo'];
|
$show_team_logo = $instance['show_team_logo'];
|
||||||
$show_full_table_link = $instance['show_full_table_link'];
|
$show_full_table_link = $instance['show_full_table_link'];
|
||||||
@@ -60,6 +63,9 @@ class SportsPress_Widget_League_Table extends WP_Widget {
|
|||||||
?>
|
?>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e( 'Number of teams to show:', 'sportspress' ); ?></label>
|
||||||
|
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo esc_attr($number); ?>" size="3"></p>
|
||||||
|
|
||||||
<p class="sp-prefs">
|
<p class="sp-prefs">
|
||||||
<?php _e( 'Columns:', 'sportspress' ); ?><br>
|
<?php _e( 'Columns:', 'sportspress' ); ?><br>
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
Reference in New Issue
Block a user