-1, 'columns' => null, 'show_full_table_link' => false, 'show_team_logo' => sportspress_array_value( $sportspress_options, 'league_table_show_team_logo', false ), 'link_posts' => sportspress_array_value( $sportspress_options, 'league_table_link_posts', false ), ); $r = wp_parse_args( $args, $defaults ); $output = '
' . '' . '' . ''; $data = sportspress_get_league_table_data( $id ); // The first row should be column labels $labels = $data[0]; // Remove the first row to leave us with the actual data unset( $data[0] ); $columns = sportspress_array_value( $r, 'columns', null ); if ( ! $columns ) $columns = get_post_meta( $id, 'sp_columns', true ); if ( ! is_array( $columns ) ) $columns = explode( ',', $columns ); $output .= ''; foreach( $labels as $key => $label ): if ( ! is_array( $columns ) || $key == 'name' || in_array( $key, $columns ) ) $output .= ''; endforeach; $output .= '' . '' . ''; $i = 0; if ( is_int( $r['number'] ) && $r['number'] > 0 ) $limit = $r['number']; foreach( $data as $team_id => $row ): if ( isset( $limit ) && $i >= $limit ) continue; $name = sportspress_array_value( $row, 'name', null ); if ( ! $name ) continue; $output .= ''; // Rank $output .= ''; if ( $r['show_team_logo'] ) $name = get_the_post_thumbnail( $team_id, 'sportspress-fit-icon', array( 'class' => 'team-logo' ) ) . ' ' . $name; if ( $r['link_posts'] ): $permalink = get_post_permalink( $team_id ); $name = '' . $name . ''; endif; $output .= ''; foreach( $labels as $key => $value ): if ( $key == 'name' ) continue; if ( ! is_array( $columns ) || in_array( $key, $columns ) ) $output .= ''; endforeach; $output .= ''; $i++; endforeach; $output .= '' . '
' . __( 'Pos', 'sportspress' ) . '' . $label . '
' . ( $i + 1 ) . '' . $name . '' . sportspress_array_value( $row, $key, '—' ) . '
'; if ( $r['show_full_table_link'] ) $output .= '' . __( 'View full table', 'sportspress' ) . ''; $output .= '
'; return apply_filters( 'sportspress_league_table', $output, $id ); } } function sportspress_league_table_shortcode( $atts ) { if ( isset( $atts['id'] ) ): $id = $atts['id']; unset( $atts['id'] ); elseif( isset( $atts[0] ) ): $id = $atts[0]; unset( $atts[0] ); else: $id = null; endif; return sportspress_league_table( $id, $atts ); } add_shortcode('league-table', 'sportspress_league_table_shortcode');