diff --git a/includes/class-sp-player.php b/includes/class-sp-player.php index 66fd0180..62c9258e 100644 --- a/includes/class-sp-player.php +++ b/includes/class-sp-player.php @@ -12,6 +12,16 @@ */ class SP_Player extends SP_Custom_Post { + /** + * Returns positions + * + * @access public + * @return array + */ + public function positions() { + return get_the_terms( $this->ID, 'sp_position' ); + } + /** * Returns current teams * diff --git a/templates/player-details.php b/templates/player-details.php index f9615dc4..ada44e4c 100644 --- a/templates/player-details.php +++ b/templates/player-details.php @@ -25,6 +25,7 @@ $countries = SP()->countries->countries; $player = new SP_Player( $id ); $nationality = $player->nationality; +$positions = $player->positions(); $current_teams = $player->current_teams(); $past_teams = $player->past_teams(); $metrics_before = $player->metrics( true ); @@ -41,13 +42,13 @@ if ( $nationality ): $common[ __( 'Nationality', 'sportspress' ) ] = $country_name ? ( $show_nationality_flags ? '' . $nationality . ' ' : '' ) . $country_name : '—'; endif; -$position_names = array(); -$positions = get_the_terms( $id, 'sp_position' ); -if ( $positions ): foreach ( $positions as $position ): - $position_names[] = $position->name; -endforeach; endif; - -$common[ __( 'Position', 'sportspress' ) ] = implode( ', ', $position_names ); +if ( $positions ): + $position_names = array(); + foreach ( $positions as $position ): + $position_names[] = $position->name; + endforeach; + $common[ __( 'Position', 'sportspress' ) ] = implode( ', ', $position_names ); +endif; $data = array_merge( $metrics_before, $common, $metrics_after ); @@ -74,14 +75,16 @@ endif; $data = apply_filters( 'sportspress_player_details', $data, $id ); -$output = '
'; +if ( sizeof( $data ) ) { + $output = '
'; -foreach( $data as $label => $value ): + foreach( $data as $label => $value ): - $output .= '
' . $label . '
' . $value . '
'; + $output .= '
' . $label . '
' . $value . '
'; -endforeach; + endforeach; -$output .= '
'; + $output .= '
'; -echo $output; + echo $output; +}