Add widget option to show view full table link in league table

This commit is contained in:
Brian Miyaji
2014-03-06 22:39:05 +11:00
parent 5ea50608a5
commit a09f97d7af
2 changed files with 17 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
$defaults = array( $defaults = array(
'columns' => null, 'columns' => null,
'show_full_table_link' => false,
); );
$r = wp_parse_args( $args, $defaults ); $r = wp_parse_args( $args, $defaults );
@@ -58,7 +59,12 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
endforeach; endforeach;
$output .= '</tbody>' . '</table>' . '</div>'; $output .= '</tbody>' . '</table>';
if ( $r['show_full_table_link'] )
$output .= '<a class="sp-league-table-link" href="' . get_permalink( $id ) . '">' . __( 'View full table', 'sportspress' ) . '</a>';
$output .= '</div>';
return apply_filters( 'sportspress_league_table', $output, $id ); return apply_filters( 'sportspress_league_table', $output, $id );

View File

@@ -10,12 +10,13 @@ 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'];
$columns = $instance['columns']; $columns = empty($instance['columns']) ? null : $instance['columns'];
$show_full_table_link = empty($instance['show_full_table_link']) ? false : $instance['show_full_table_link'];
echo $before_widget; echo $before_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 ) ); echo sportspress_league_table( $id, array( 'columns' => $columns, 'show_full_table_link' => $show_full_table_link ) );
echo '</div>'; echo '</div>';
echo $after_widget; echo $after_widget;
} }
@@ -25,15 +26,17 @@ class SportsPress_Widget_League_Table extends WP_Widget {
$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['columns'] = (array)$new_instance['columns']; $instance['columns'] = (array)$new_instance['columns'];
$instance['show_full_table_link'] = $new_instance['show_full_table_link'];
return $instance; return $instance;
} }
function form( $instance ) { function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'columns' => null ) ); $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '', 'columns' => null, 'show_full_table_link' => true ) );
$title = strip_tags($instance['title']); $title = strip_tags($instance['title']);
$id = intval($instance['id']); $id = intval($instance['id']);
$columns = $instance['columns']; $columns = $instance['columns'];
$show_full_table_link = $instance['show_full_table_link'];
?> ?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label> <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> <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>
@@ -73,6 +76,10 @@ class SportsPress_Widget_League_Table extends WP_Widget {
<label class="button"><input name="<?php echo $field_name; ?>" type="checkbox" id="<?php echo $field_id . '-' . $column->post_name; ?>" value="<?php echo $column->post_name; ?>" <?php if ( $columns === null || in_array( $column->post_name, $columns ) ): ?>checked="checked"<?php endif; ?>><?php echo $column->post_title; ?></label> <label class="button"><input name="<?php echo $field_name; ?>" type="checkbox" id="<?php echo $field_id . '-' . $column->post_name; ?>" value="<?php echo $column->post_name; ?>" <?php if ( $columns === null || in_array( $column->post_name, $columns ) ): ?>checked="checked"<?php endif; ?>><?php echo $column->post_title; ?></label>
<?php endforeach; ?> <?php endforeach; ?>
</p> </p>
<p><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_full_table_link'); ?>" name="<?php echo $this->get_field_name('show_full_table_link'); ?>" value="1" <?php checked( $show_full_table_link, 1 ); ?>>
<label for="<?php echo $this->get_field_id('show_full_table_link'); ?>"><?php _e( 'Display link to view full table', 'sportspress' ); ?></label></p>
<?php <?php
} }
} }