How to edit the output of the standings

If you’re running a league, standings are one of the most important parts of your league. After all, they tell teams where they stand in the league.

The standings in Sports Bench come in prepackaged formats, ready to go without any code from you. But sometimes they aren’t quite enough. Maybe you want to add some other stats displayed inside the standings as well. Fortunately, there is a way to easily accomplish these changes.

Here’s how to make changes to the standings.

Basic changes

First off, you can make quick changes to the way standings look on your standings page by using the custom fields that appear when you select the standings page template or shortcode (or multi-select dropdown in the standings block attribute if you’re using Gutenberg).

These fields allow you to add in the goals/runs/points for, against and differential, the home, away, conference and division record. You can add all of them or just some of them. Just know that these will be hidden on mobile screen sizes for design purposes by default.

If you don’t know any or a lot of PHP to where you feel comfortable diving into code, this is going to be your best bet for changing the way standings show up.

Filters you’ll be using

Like other customizations in Sports Bench, the easiest way to customize the standings output is through filters. Again, if you haven’t already, make sure you’re familiar with filters in WordPress and how they work.

The filters you’ll be using to change the data that is output in the standings tables are as follows.

There are also other filters that help add or change styles for the tables, which you can also find here.

Changing the filters to get your output

Now comes the fun part: changing the output of the filters to get your desired table. For now, we’ll be using the sports_bench_standings_table filter to walk you through how to make these changes.

This filter has six parameters to use: the HTML that’s already been run, the teams that are being displayed, the division/conference id that’s being shown (this is 0 if it’s the entire league standings), the sport that the site is using, the type of standing being shown (league, conference or division) and an array of items from the standings custom fields.

So here’s the filter in action for a soccer site and showing the entire league.

function sports_bench_do_standings_table( $html, $teams, $division, $sport, $type, $items ) {

$standings = [];
foreach ( $teams as $team ) {
$the_team = new Sports_Bench_Team( (int) $team->team_id );
$standing = array(
'team_id' => $the_team->team_id,
'team_name' => $the_team->team_name,
'team_link' => $the_team->get_permalink(),
'games_played' => $the_team->get_games_played( '"' . get_option( 'sports-bench-season-year' ) . '"' ),
'wins' => $the_team->get_wins( '"' . get_option( 'sports-bench-season-year' ) . '"' ),
'losses' => $the_team->get_losses( '"' . get_option( 'sports-bench-season-year' ) . '"' ),
'draws' => $the_team->get_draws( '"' . get_option( 'sports-bench-season-year' ) . '"' ),
'points' => sports_bench_get_points( $the_team->team_id )
);
if ( $items ) {
foreach ( $items as $item ) {
if ( $item['sports_bench_standings_items'] == 'goals-for' ) {
$standing['goals-for'] = $the_team->get_points_for( '"' . get_option( 'sports-bench-season-year' ) . '"' );
}
if ( $item['sports_bench_standings_items'] == 'goals-against' ) {
$standing['goals-against'] = $the_team->get_points_against( '"' . get_option( 'sports-bench-season-year' ) . '"' );
}
if ( $item['sports_bench_standings_items'] == 'goals-differential' ) {
$standing['goal-differential'] = $the_team->get_point_differential( '"' . get_option( 'sports-bench-season-year' ) . '"' );
}
if ( $item['sports_bench_standings_items'] == 'home-record' ) {
$standing['home-record'] = $the_team->get_home_record( '"' . get_option( 'sports-bench-season-year' ) . '"' );
}
if ( $item['sports_bench_standings_items'] == 'away-record' ) {
$standing['away-record'] = $the_team->get_road_record( '"' . get_option( 'sports-bench-season-year' ) . '"' );
}
if ( $item['sports_bench_standings_items'] == 'division-record' ) {
$standing['division-record'] = $the_team->get_division_record( '"' . get_option( 'sports-bench-season-year' ) . '"' );
}
if ( $item['sports_bench_standings_items'] == 'conference-record' ) {
$standing['conference-record'] = $the_team->get_conference_record( '"' . get_option( 'sports-bench-season-year' ) . '"' );
}
}
}
array_push( $standings, $standing );
}
foreach ( $standings as $key => $row ) {
$points[ $key ] = $row[ 'points' ];
}
array_multisort( $points, SORT_DESC, $standings );

$table_head_styles = apply_filters( 'sports_bench_standings_head_row', '', $division[ 0 ] );
$html = '<table class="standings">';
$html .= '<thead>';
$html .= '<tr style="' . $table_head_styles . '">';
$html .= '<th class="left">' . $division[ 0 ]->division_name . '</th>';
$html .= '<th>' . __( 'GP', 'sports-bench' ) . '</th>';
$html .= '<th>' . __( 'W', 'sports-bench' ) . '</th>';
$html .= '<th>' . __( 'D', 'sports-bench' ) . '</th>';
$html .= '<th>' . __( 'L', 'sports-bench' ) . '</th>';
$html .= '<th>' . __( 'PTS', 'sports-bench' ) . '</th>';
if ( $items ) {
foreach ( $items as $item ) {
if ( $item['sports_bench_standings_items'] == 'goals-for' ) {
$html .= '<th class="show-for-medium">' . __( 'GF', 'sports-bench' ) . '</th>';
continue;
}
if ( $item['sports_bench_standings_items'] == 'goals-against' ) {
$html .= '<th class="show-for-medium">' . __( 'GA', 'sports-bench' ) . '</th>';
continue;
}
if ( $item['sports_bench_standings_items'] == 'goals-differential' ) {
$html .= '<th class="show-for-medium">' . __( 'GD', 'sports-bench' ) . '</th>';
continue;
}
if ( $item['sports_bench_standings_items'] == 'home-record' ) {
$html .= '<th class="show-for-medium">' . __( 'HOME', 'sports-bench' ) . '</th>';
continue;
}
if ( $item['sports_bench_standings_items'] == 'away-record' ) {
$html .= '<th class="show-for-medium">' . __( 'AWAY', 'sports-bench' ) . '</th>';
continue;
}
if ( $item['sports_bench_standings_items'] == 'division-record' ) {
$html .= '<th class="show-for-medium">' . __( 'DIV', 'sports-bench' ) . '</th>';
continue;
}
if ( $item['sports_bench_standings_items'] == 'conference-record' ) {
$html .= '<th class="show-for-medium">' . __( 'CONF', 'sports-bench' ) . '</th>';
continue;
}
}
}
$html .= '</tr>';
$html .= '</thead>';
$html .= '<tbody>';
foreach ( $standings as $team ) {
$table_team_styles = apply_filters( 'sports_bench_standings_team_row', '', $team[ 'team_id' ] );
$html .= '<tr style="' . $table_team_styles . '">';
$html .= '<td><a href="' . $team[ 'team_link' ] . '">' . $team[ 'team_name' ] . '</a></td>';
$html .= '<td class="center">' . $team[ 'games_played' ] . '</td>';
$html .= '<td class="center">' . $team[ 'wins' ] . '</td>';
$html .= '<td class="center">' . $team[ 'draws' ] . '</td>';
$html .= '<td class="center">' . $team[ 'losses' ] . '</td>';
$html .= '<td class="center">' . $team[ 'points' ] . '</td>';
if ( isset( $team[ 'goals-for' ] ) ) {
$html .= '<td class="center show-for-medium">' . $team[ 'goals-for' ] . '</td>';
}
if ( isset( $team[ 'goals-against' ] ) ) {
$html .= '<td class="center show-for-medium">' . $team[ 'goals-against' ] . '</td>';
}
if ( isset( $team[ 'goal-differential' ] ) ) {
$html .= '<td class="center show-for-medium">' . $team[ 'goal-differential' ] . '</td>';
}
if ( isset( $team[ 'home-record' ] ) ) {
$html .= '<td class="center show-for-medium">' . $team[ 'home-record' ][ 0 ] . '-' . $team[ 'home-record' ][ 1 ] . '-' . $team[ 'home-record' ][ 2 ] . '</td>';
}
if ( isset( $team[ 'away-record' ] ) ) {
$html .= '<td class="center show-for-medium">' . $team[ 'away-record' ][ 0 ] . '-' . $team[ 'away-record' ][ 1 ] . '-' . $team[ 'away-record' ][ 2 ] . '</td>';
}
if ( isset( $team[ 'division-record' ] ) ) {
$html .= '<td class="center show-for-medium">' . $team[ 'division-record' ][ 0 ] . '-' . $team[ 'division-record' ][ 1 ] . '-' . $team[ 'division-record' ][ 2 ] . '</td>';
}
if ( isset( $team[ 'conference-record' ] ) ) {
$html .= '<td class="center show-for-medium">' . $team[ 'conference-record' ][ 0 ] . '-' . $team[ 'conference-record' ][ 1 ] . '-' . $team[ 'conference-record' ][ 2 ] . '</td>';
}
$html .= '</tr>';
}
$html .= '</tbody>';
$html .= '</table>';
}

So something that you can do is to add other stats for teams at the , like potentially neutral site records, record against other conferences or divisions or even other team-related stats. You’ll want to add these during the initial loop through the teams. Then you can output them like the other standings items to create the standings that you want.