Add player list widget and add league table widget columns selector

This commit is contained in:
Brian Miyaji
2014-02-12 04:30:16 +11:00
parent 08b6111fb2
commit cacbd3c27e
11 changed files with 300 additions and 63 deletions

View File

@@ -6,34 +6,12 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
$id = get_the_ID();
$defaults = array(
'number_label' => __( 'Pos', 'sportspress' ),
'thumbnails' => 0,
'thumbnail_size' => 'thumbnail'
'columns' => null,
);
$r = wp_parse_args( $args, $defaults );
$leagues = get_the_terms( $id, 'sp_league' );
$seasons = get_the_terms( $id, 'sp_season' );
$terms = array();
if ( $leagues ):
$league = reset( $leagues );
$terms[] = $league->name;
endif;
if ( $seasons ):
$season = reset( $seasons );
$terms[] = $season->name;
endif;
$title = sizeof( $terms ) ? implode( ' — ', $terms ) : get_the_title( $id );
if ( ! is_singular( 'sp_table' ) )
$output = '<h4 class="sp-table-caption"><a href="' . get_permalink( $id ) . '">' . $title . '</a></h4>';
else
$output = '<h4 class="sp-table-caption">' . $title . '</h4>';
$output .= '<div class="sp-table-wrapper">' .
$output = '<div class="sp-table-wrapper">' .
'<table class="sp-league-table sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
$data = sportspress_get_league_table_data( $id );
@@ -44,9 +22,13 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
// Remove the first row to leave us with the actual data
unset( $data[0] );
$output .= '<th class="data-number">' . $r['number_label'] . '</th>';
$columns = sportspress_array_value( $r, 'columns', null );
$output .= '<th class="data-number">' . __( 'Pos', 'sportspress' ) . '</th>';
foreach( $labels as $key => $label ):
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
if ( ! is_array( $columns ) || $key == 'name' || in_array( $key, $columns ) )
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
@@ -57,23 +39,17 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
// Position as number
$output .= '<td class="data-number">' . ( $i + 1 ) . '</td>';
// Rank
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
// Thumbnail and name as link
$permalink = get_post_permalink( $team_id );
if ( $r['thumbnails'] ):
$thumbnail = get_the_post_thumbnail( $team_id, $r['thumbnail_size'], array( 'class' => 'logo' ) );
else:
$thumbnail = null;
endif;
$name = sportspress_array_value( $row, 'name', sportspress_array_value( $row, 'name', '&nbsp;' ) );
$output .= '<td class="data-name">' . ( $thumbnail ? $thumbnail . ' ' : '' ) . '<a href="' . $permalink . '">' . $name . '</a></td>';
$output .= '<td class="data-name"><a href="' . get_post_permalink( $team_id ) . '">' . $name . '</a></td>';
foreach( $labels as $key => $value ):
if ( $key == 'name' )
continue;
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '&mdash;' ) . '</td>';
if ( ! is_array( $columns ) || in_array( $key, $columns ) )
$output .= '<td class="data-' . $key . '">' . sportspress_array_value( $row, $key, '&mdash;' ) . '</td>';
endforeach;
$output .= '</tr>';
@@ -84,7 +60,7 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
$output .= '</tbody>' . '</table>' . '</div>';
return apply_filters( 'sportspress_league_table', $output );
return apply_filters( 'sportspress_league_table', $output, $id );
}
}