From fefc8790f7290f81b7ef507bdcab0c36e652b07d Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sun, 19 Jul 2015 13:08:38 +1000 Subject: [PATCH] Display multiple current teams in staff details --- includes/class-sp-staff.php | 10 ++++++++++ templates/staff-details.php | 18 ++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/includes/class-sp-staff.php b/includes/class-sp-staff.php index 6802486d..46894189 100644 --- a/includes/class-sp-staff.php +++ b/includes/class-sp-staff.php @@ -12,6 +12,16 @@ */ class SP_Staff extends SP_Custom_Post { + /** + * Returns current teams + * + * @access public + * @return array + */ + public function current_teams() { + return get_post_meta( $this->ID, 'sp_current_team', false ); + } + /** * Returns past teams * diff --git a/templates/staff-details.php b/templates/staff-details.php index eb6f2100..315244be 100644 --- a/templates/staff-details.php +++ b/templates/staff-details.php @@ -15,6 +15,7 @@ if ( ! isset( $id ) ) $defaults = array( 'show_nationality_flags' => get_option( 'sportspress_staff_show_flags', 'yes' ) == 'yes' ? true : false, + 'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false, ); extract( $defaults, EXTR_SKIP ); @@ -24,7 +25,7 @@ $countries = SP()->countries->countries; $staff = new SP_Staff( $id ); $nationality = $staff->nationality; -$current_team = $staff->current_team; +$current_teams = $staff->current_teams(); $past_teams = $staff->past_teams(); $data = array(); @@ -38,13 +39,22 @@ if ( $nationality ): $data[ __( 'Nationality', 'sportspress' ) ] = $country_name ? ( $show_nationality_flags ? '' . $nationality . ' ' : '' ) . $country_name : '—'; endif; -if ( $current_team ) - $data[ __( 'Current Team', 'sportspress' ) ] = '' . get_the_title( $current_team ) . ''; +if ( $current_teams ): + $teams = array(); + foreach ( $current_teams as $team ): + $team_name = get_the_title( $team ); + if ( $link_teams ) $team_name = '' . $team_name . ''; + $teams[] = $team_name; + endforeach; + $data[ __( 'Current Team', 'sportspress' ) ] = implode( ', ', $teams ); +endif; if ( $past_teams ): $teams = array(); foreach ( $past_teams as $team ): - $teams[] = '' . get_the_title( $team ) . ''; + $team_name = get_the_title( $team ); + if ( $link_teams ) $team_name = '' . $team_name . ''; + $teams[] = $team_name; endforeach; $data[ __( 'Past Teams', 'sportspress' ) ] = implode( ', ', $teams ); endif;