Add ability to display staff members in team page

This commit is contained in:
Brian Miyaji
2015-12-29 15:49:01 +11:00
parent 16b8e17c11
commit 331634a65f
6 changed files with 204 additions and 0 deletions

View File

@@ -165,6 +165,13 @@ class SP_Admin_Meta_Boxes {
'context' => 'normal', 'context' => 'normal',
'priority' => 'low', 'priority' => 'low',
), ),
'staff' => array(
'title' => __( 'Staff', 'sportspress' ),
'save' => 'SP_Meta_Box_Team_Staff::save',
'output' => 'SP_Meta_Box_Team_Staff::output',
'context' => 'normal',
'priority' => 'high',
),
), ),
'sp_player' => array( 'sp_player' => array(
'shortcode' => array( 'shortcode' => array(

View File

@@ -0,0 +1,116 @@
<?php
/**
* Team Player Staff
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.9.12
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Team_Staff
*/
class SP_Meta_Box_Team_Staff {
/**
* Output the metabox
*/
public static function output( $post ) {
global $pagenow;
if ( $pagenow != 'post-new.php' ):
$team = new SP_Team( $post );
list( $data, $checked ) = $team->staff( true );
self::table( $data, $checked );
else:
printf( __( 'No results found.', 'sportspress' ) );
endif;
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
sp_update_post_meta_recursive( $post_id, 'sp_staff', sp_array_value( $_POST, 'sp_staff', array() ) );
}
/**
* Admin edit table
*/
public static function table( $data = array(), $checked = array() ) {
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table sp-team-staff-table sp-select-all-range">
<thead>
<tr>
<th class="check-column"><input class="sp-select-all" type="checkbox"></th>
<th class="column-staff">
<?php _e( 'Staff', 'sportspress' ); ?>
</th>
<th class="column-role">
<?php _e( 'Job', 'sportspress' ); ?>
</th>
<th class="column-league">
<?php _e( 'Competition', 'sportspress' ); ?>
</th>
<th class="column-season">
<?php _e( 'Season', 'sportspress' ); ?>
</th>
</tr>
</thead>
<tbody>
<?php
if ( is_array( $data ) ):
if ( sizeof( $data ) > 0 ):
$i = 0;
foreach ( $data as $staff ):
$role = get_post_meta( $staff->ID, 'sp_role', true );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<input type="checkbox" name="sp_staff[]" id="sp_staff_<?php echo $staff->ID; ?>" value="<?php echo $staff->ID; ?>" <?php checked( in_array( $staff->ID, $checked ) ); ?>>
</td>
<td>
<a href="<?php echo get_edit_post_link( $staff->ID ); ?>">
<?php echo $staff->post_title; ?>
</a>
</td>
<td><?php echo get_the_terms ( $staff->ID, 'sp_role' ) ? the_terms( $staff->ID, 'sp_role' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms ( $staff->ID, 'sp_league' ) ? the_terms( $staff->ID, 'sp_league' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms ( $staff->ID, 'sp_season' ) ? the_terms( $staff->ID, 'sp_season' ) : '&mdash;'; ?></td>
</tr>
<?php
$i++;
endforeach;
else:
?>
<tr class="sp-row alternate">
<td colspan="4">
<?php _e( 'No results found.', 'sportspress' ); ?>
</td>
</tr>
<?php
endif;
else:
?>
<tr class="sp-row alternate">
<td colspan="4">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
</td>
</tr>
<?php
endif;
?>
</tbody>
</table>
</div>
<?php
}
}

View File

@@ -345,6 +345,40 @@ class SP_Team extends SP_Custom_Post {
return array( $columns, $data, $placeholders ); return array( $columns, $data, $placeholders );
} }
/**
* Returns staff members
*
* @access public
* @return array
*/
public function staff( $admin = false ) {
if ( ! $this->ID ) return null;
$args = array(
'post_type' => 'sp_staff',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_key' => 'sp_team',
'meta_value' => $this->ID,
);
$members = get_posts( $args );
$checked = (array) get_post_meta( $this->ID, 'sp_staff' );
if ( $admin ):
return array( $members, $checked );
else:
foreach ( $members as $key => $member ):
if ( ! in_array( $member->ID, $checked ) ):
unset( $members[ $key ] );
endif;
endforeach;
return $members;
endif;
}
/** /**
* Returns player lists * Returns player lists
* *

View File

@@ -259,6 +259,19 @@ if ( ! function_exists( 'sportspress_output_team_details' ) ) {
sp_get_template( 'team-details.php' ); sp_get_template( 'team-details.php' );
} }
} }
if ( ! function_exists( 'sportspress_output_team_staff' ) ) {
/**
* Output the team staff.
*
* @access public
* @subpackage Team/Staff
* @return void
*/
function sportspress_output_team_staff() {
sp_get_template( 'team-staff.php' );
}
}
if ( ! function_exists( 'sportspress_output_team_tables' ) ) { if ( ! function_exists( 'sportspress_output_team_tables' ) ) {
/** /**

View File

@@ -72,11 +72,13 @@ add_action( 'sportspress_before_single_team', 'sportspress_output_post_excerpt',
* *
* @see sportspress_output_team_link() * @see sportspress_output_team_link()
* @see sportspress_output_team_details() * @see sportspress_output_team_details()
* @see sportspress_output_team_staff()
* @see sportspress_output_team_lists() * @see sportspress_output_team_lists()
* @see sportspress_output_team_tables() * @see sportspress_output_team_tables()
*/ */
add_action( 'sportspress_single_team_content', 'sportspress_output_team_link', 0 ); add_action( 'sportspress_single_team_content', 'sportspress_output_team_link', 0 );
add_action( 'sportspress_single_team_content', 'sportspress_output_team_details', 10 ); add_action( 'sportspress_single_team_content', 'sportspress_output_team_details', 10 );
add_action( 'sportspress_single_team_content', 'sportspress_output_team_staff', 15 );
add_action( 'sportspress_single_team_content', 'sportspress_output_team_lists', 20 ); add_action( 'sportspress_single_team_content', 'sportspress_output_team_lists', 20 );
add_action( 'sportspress_single_team_content', 'sportspress_output_team_tables', 30 ); add_action( 'sportspress_single_team_content', 'sportspress_output_team_tables', 30 );

32
templates/team-staff.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
/**
* Team Staff
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 1.9.12
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! isset( $id ) )
$id = get_the_ID();
$team = new SP_Team( $id );
$members = $team->staff();
foreach ( $members as $staff ):
$id = $staff->ID;
$name = $staff->post_title;
$staff = new SP_Staff( $id );
$role = $staff->role();
if ( $role )
$name = '<span class="sp-staff-role">' . $role->name . '</span> ' . $name;
?>
<h4 class="sp-staff-name"><?php echo $name; ?></h4>
<?php
sp_get_template( 'staff-photo.php', array( 'id' => $id ) );
sp_get_template( 'staff-details.php', array( 'id' => $id ) );
endforeach;