Hide player details section if none available
This commit is contained in:
@@ -12,6 +12,16 @@
|
|||||||
*/
|
*/
|
||||||
class SP_Player extends SP_Custom_Post {
|
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
|
* Returns current teams
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ $countries = SP()->countries->countries;
|
|||||||
$player = new SP_Player( $id );
|
$player = new SP_Player( $id );
|
||||||
|
|
||||||
$nationality = $player->nationality;
|
$nationality = $player->nationality;
|
||||||
|
$positions = $player->positions();
|
||||||
$current_teams = $player->current_teams();
|
$current_teams = $player->current_teams();
|
||||||
$past_teams = $player->past_teams();
|
$past_teams = $player->past_teams();
|
||||||
$metrics_before = $player->metrics( true );
|
$metrics_before = $player->metrics( true );
|
||||||
@@ -41,13 +42,13 @@ if ( $nationality ):
|
|||||||
$common[ __( 'Nationality', 'sportspress' ) ] = $country_name ? ( $show_nationality_flags ? '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/flags/' . strtolower( $nationality ) . '.png" alt="' . $nationality . '"> ' : '' ) . $country_name : '—';
|
$common[ __( 'Nationality', 'sportspress' ) ] = $country_name ? ( $show_nationality_flags ? '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/flags/' . strtolower( $nationality ) . '.png" alt="' . $nationality . '"> ' : '' ) . $country_name : '—';
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
$position_names = array();
|
if ( $positions ):
|
||||||
$positions = get_the_terms( $id, 'sp_position' );
|
$position_names = array();
|
||||||
if ( $positions ): foreach ( $positions as $position ):
|
foreach ( $positions as $position ):
|
||||||
$position_names[] = $position->name;
|
$position_names[] = $position->name;
|
||||||
endforeach; endif;
|
endforeach;
|
||||||
|
$common[ __( 'Position', 'sportspress' ) ] = implode( ', ', $position_names );
|
||||||
$common[ __( 'Position', 'sportspress' ) ] = implode( ', ', $position_names );
|
endif;
|
||||||
|
|
||||||
$data = array_merge( $metrics_before, $common, $metrics_after );
|
$data = array_merge( $metrics_before, $common, $metrics_after );
|
||||||
|
|
||||||
@@ -74,14 +75,16 @@ endif;
|
|||||||
|
|
||||||
$data = apply_filters( 'sportspress_player_details', $data, $id );
|
$data = apply_filters( 'sportspress_player_details', $data, $id );
|
||||||
|
|
||||||
$output = '<div class="sp-template sp-template-player-details sp-template-details"><div class="sp-list-wrapper"><dl class="sp-player-details">';
|
if ( sizeof( $data ) ) {
|
||||||
|
$output = '<div class="sp-template sp-template-player-details sp-template-details"><div class="sp-list-wrapper"><dl class="sp-player-details">';
|
||||||
|
|
||||||
foreach( $data as $label => $value ):
|
foreach( $data as $label => $value ):
|
||||||
|
|
||||||
$output .= '<dt>' . $label . '</dt><dd>' . $value . '</dd>';
|
$output .= '<dt>' . $label . '</dt><dd>' . $value . '</dd>';
|
||||||
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
$output .= '</dl></div></div>';
|
$output .= '</dl></div></div>';
|
||||||
|
|
||||||
echo $output;
|
echo $output;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user