How to customize the game recap information

The game information section of the game recap is a pretty important part of the Sports Bench experience. It’s here where people can see exactly what happened in the game and who did what.

By default, this section has a lot of basic information that tells the basic story. But if you’re good with stats or just want to add and/or remove stats, you might want to change them.

Fortunately, with Sports Bench and filters, that’s pretty easy to do.

Filters you’ll be using

Like the standings, scoreboard and stats, the best way to change the output of the information inside of game recaps is to use the available filters. Again, if you don’t know what filters are in WordPress, it’s recommended that you read up on them before continuing on.

But if you are ready to start using the filters, here are the filters you can use to manipulate the game recap information. We’ll go over a couple of examples in the next section.

Game recap examples

So let’s first start small and just change the basic information for the game. This goes in the same section as the linescore and is one of the first things people do. Normally, this section shows . But with the sports_bench_game_info filter, you can put whatever you want here.

function sports_bench_do_game_info( $html, $game, $home_team ) {
$datetime = date_create( $game->game_day );
$datetime = date_format( $datetime, 'g:i a, F j, Y' );

if ( $game->game_attendance != null ) {
$html .= '<h3 class="game-info">' . __( 'Attendance: ', 'sports-bench' ) . $game->game_attendance . '</h3>';
}
$html .= '<h3 class="game-info">' . $datetime . '</h3>';
$html .= '<h3 class="game-info">' . $game->game_location_stadium . ', ' . $game->game_location_city . ', ' . $game->game_location_state . '</h3>';

return $html;
}
add_filter( 'sports_bench_game_info', 'sports_bench_do_game_info', 10, 3 );

Some things you can do here is display a Google Map for the stadium (although that’s built in), display more information about the teams playing or basically anything else.

Now, where can you go from here? Well, if you’re trying to customize this section, you might want to try to change the stats that are shown for teams. To accomplish this, you use the sports_bench_team_stats table.

function sports_bench_do_team_stats( $html, $game_info, $away_team, $home_team, $game, $sport ) {
foreach ( $game_info as $info ) {
$html = '<table class="team-stats">';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th></th>';
$html .= '<th style="' . apply_filters( 'sports_bench_game_recap_team_stats_head_cell', '', $away_team ) . '">' . $home_team->get_team_photo( 'team-logo' ) . '</th>';
$html .= '<th style="' . apply_filters( 'sports_bench_game_recap_team_stats_head_cell', '', $home_team ) . '">' . $away_team->get_team_photo( 'team-logo' ) . '</th>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<th></th>';
$html .= '<th style="' . apply_filters( 'sports_bench_game_recap_team_stats_head_cell', '', $away_team ) . '">' . $home_team->team_abbreviation . '</th>';
$html .= '<th style="' . apply_filters( 'sports_bench_game_recap_team_stats_head_cell', '', $home_team ) . '">' . $away_team->team_abbreviation . '</th>';
$html .= '</tr>';
$html .= '</thead>';
$html .= '<tbody>';
$html .= '<tr>';
$html .= '<td>' . __( 'Possession:', 'sports-bench' ) . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $away_team ) . '">' . $info->game_home_possession . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $home_team ) . '">' . $info->game_away_possession . '</td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td>' . __( 'Shots:', 'sports-bench' ) . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $away_team ) . '">' . $info->game_home_shots . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $home_team ) . '">' . $info->game_away_shots . '</td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td>' . __( 'Shots on goal:', 'sports-bench' ) . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $away_team ) . '">' . $info->game_home_sog . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $home_team ) . '">' . $info->game_away_sog . '</td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td>' . __( 'Corners:', 'sports-bench' ) . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $away_team ) . '">' . $info->game_home_corners . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $home_team ) . '">' . $info->game_away_corners . '</td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td>' . __( 'Offsides:', 'sports-bench' ) . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $away_team ) . '">' . $info->game_home_offsides . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $home_team ) . '">' . $info->game_away_offsides . '</td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td>' . __( 'Fouls:', 'sports-bench' ) . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $away_team ) . '">' . $info->game_home_fouls . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $home_team ) . '">' . $info->game_away_fouls . '</td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td>' . __( 'Saves:', 'sports-bench' ) . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $away_team ) . '">' . $info->game_home_saves . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $home_team ) . '">' . $info->game_away_saves . '</td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td>' . __( 'Yellow cards:', 'sports-bench' ) . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $away_team ) . '">' . $info->game_home_yellow . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $home_team ) . '">' . $info->game_away_yellow . '</td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td>' . __( 'Red cards:', 'sports-bench' ) . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $away_team ) . '">' . $info->game_home_red . '</td>';
$html .= '<td class="stat" style="' . apply_filters( 'sports_bench_game_recap_team_stats_cell', '', $home_team ) . '">' . $info->game_away_red . '</td>';
$html .= '</tr>';
$html .= '</tbody>';
$html .= '</table>';
}
return $html;
}
add_filter( 'sports_bench_team_stats', 'sports_bench_do_team_stats', 10, 6 );

From here you can remove team stats to be shown or calculate and add your own stats. Basically, if you know what you’re doing, you can do anything. It’s a similar process for individual stats.

So there you have it! You can now change and customize the information that is shown in a game recap. And that adds another layer that separates your site from someone else’s.

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept the Privacy Policy

This site uses Akismet to reduce spam. Learn how your comment data is processed.