How to edit the stats output

Finally, another area that you might want to customize are the stats tables. There are three areas of stats that you can customize the output: the stats page template/shortcode, team pages and player pages.

Like the other customizations, this is pretty easy if you know PHP and filters in WordPress.

Filters you’ll be using

Yes, we’re talking about filters again. They help to make customizations so much easier on your end. So again, if you have no idea what I’m talking when I say filters, please read up on what they are and how they are used in WordPress.

In the meantime, here are the filters you can use to change the data output for the stats.

We’ll use these to change the output of the various areas.

Changing the stats page filters for your needs

One of the areas you can easily change are the tables on the stats leaderboard page template/shortcode. Here you might want to remove the team logo or link to the player’s page or add in more information about the team or player being shown.

Here’s the default setup for the leaders table.

function sports_bench_do_stat_leader_table( $html, $stats, $stat, $type ) {

if ( 'first' == $type ) {
$html .= '<table id="' . $stat . '" class="stat-table">';
$html .= '<thead>';
$table_head_style = apply_filters( 'sports_bench_stats_head_row', '', $stat );
$html .= '<tr style="' . $table_head_style . '">';
$html .= '<th class="left" colspan="3">' . sports_bench_get_stat_title( $stat ) . '</th>';
$html .= '</tr>';
$html .= '</thead>';
$html .= '<tbody>';
$count = 1;
foreach ( $stats as $player ) {
$the_player = new Sports_Bench_Player( (int) $player[ 'player_id' ] );
$team = new Sports_Bench_Team( (int) $the_player->team_id );
$table_row_style = apply_filters( 'sports_bench_stats_player_row', '', $player, $team, $stat );
$html .= '<tr style="' . $table_row_style . '">';
$html .= '<td>' . $team->get_team_photo( 'team-logo' ) . '</td>';
$html .= '<td><a href="' . $the_player->get_permalink() . ' ">' . $the_player->player_first_name . ' ' . $the_player->player_last_name . '</a></td>';
$html .= '<td class="center">' . $player[ 'stat' ] . '</td>';
$html .= '</tr>';
if ( $count == 10 ) {
break;
}
$count++;
}
$html .= '</tbody>';
$html .= '</table>';
$html .= '<a class="button black stat-button">' . __( 'Load More', 'sports-bench' ) . '</a>';
} else {
$count = 1;
foreach ( $stats as $player ) {
$the_player = new Sports_Bench_Player( (int) $player[ 'player_id' ] );
$team = new Sports_Bench_Team( (int) $the_player->team_id );
$table_row_style = apply_filters( 'sports_bench_stats_player_row', '', $player, $team, $stat );
$html .= '<tr style="' . $table_row_style . '">';
$html .= '<td>' . $team->get_team_photo( 'team-logo' ) . '</td>';
$html .= '<td>' . $the_player->player_first_name . ' ' . $the_player->player_last_name . '</td>';
$html .= '<td class="center">' . $player[ 'stat' ] . '</td>';
$html .= '</tr>';
if ( $count == 10 ) {
break;
}
$count++;
}
}

return $html;
}
add_filter( 'sports_bench_stat_leader_table', 'sports_bench_do_stat_leader_table', 10, 4 );

This one is a bit tricky because there is a required bit. you must keep the conditional that checks to see if this is the first 10 players that load with the page or if the user has clicked load more to load ten more players to the table. Otherwise, just make sure that the columns align on both sides of the conditional.

Changing the team/player stats filters for your needs

You can also change the tables on the team and player pages. The process for this is similar to the stats table. You can add your own items or you can remove items that you don’t need. Just keep in mind how the table work at smaller screen sizes.

Also, the table on the player page has a bit of a trick to it. If you change the number of columns in either the sports_bench_player_stats_table filter or the sports_bench_player_game_stats_table filter, you need to make sure the other filter’s table has the same number of columns. Otherwise things will look weird. Trust me.

Otherwise, go forth and customize your stats table to make them meet what you need them too.