Add player and staff dropdown templates to layout designer

This commit is contained in:
Brian Miyaji
2016-10-20 13:41:27 +11:00
parent bf7e201eae
commit e352d1a5b1
8 changed files with 197 additions and 135 deletions

View File

@@ -23,6 +23,10 @@
.sp-template {
margin-bottom: 1.5em;
}
.sp-template-dropdown {
clear: both;
overflow: hidden;
}
.sp-template-logo,
.sp-template-photo {
float: left;

View File

@@ -59,14 +59,6 @@ class SP_Settings_Players extends SP_Settings_Page {
'type' => 'checkbox',
),
array(
'title' => __( 'Dropdown', 'sportspress' ),
'desc' => __( 'Display dropdown', 'sportspress' ),
'id' => 'sportspress_player_show_selector',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Details', 'sportspress' ),
'desc' => __( 'Squad Number', 'sportspress' ),

View File

@@ -59,14 +59,6 @@ class SP_Settings_Staff extends SP_Settings_Page {
'type' => 'checkbox',
),
array(
'title' => __( 'Dropdown', 'sportspress' ),
'desc' => __( 'Display dropdown', 'sportspress' ),
'id' => 'sportspress_staff_show_selector',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Details', 'sportspress' ),
'desc' => __( 'Nationality', 'sportspress' ),

View File

@@ -171,6 +171,12 @@ class SP_Templates {
),
'player' => array_merge(
apply_filters( 'sportspress_before_player_template', array(
'selector' => array(
'title' => __( 'Dropdown', 'sportspress' ),
'option' => 'sportspress_player_show_selector',
'action' => 'sportspress_output_player_selector',
'default' => 'yes',
),
'photo' => array(
'title' => __( 'Photo', 'sportspress' ),
'option' => 'sportspress_player_show_photo',
@@ -232,6 +238,12 @@ class SP_Templates {
),
'staff' => array_merge(
apply_filters( 'sportspress_before_staff_template', array(
'selector' => array(
'title' => __( 'Dropdown', 'sportspress' ),
'option' => 'sportspress_staff_show_selector',
'action' => 'sportspress_output_staff_selector',
'default' => 'yes',
),
'photo' => array(
'title' => __( 'Photo', 'sportspress' ),
'option' => 'sportspress_staff_show_photo',

View File

@@ -335,7 +335,20 @@ if ( ! function_exists( 'sportspress_output_league_table' ) ) {
/** Single Player ********************************************************/
if ( ! function_exists( 'sportspress_output_player_photo' ) ) {
if ( ! function_exists( 'sportspress_output_player_selector' ) ) {
/**
* Output the player dropdown.
*
* @access public
* @subpackage Player/Dropdown
* @return void
*/
function sportspress_output_player_selector() {
sp_get_template( 'player-selector.php' );
}
}
if ( ! function_exists( 'sportspress_output_player_selector' ) ) {
/**
* Output the player photo.
@@ -398,6 +411,19 @@ if ( ! function_exists( 'sportspress_output_player_list' ) ) {
/** Single Staff ********************************************************/
if ( ! function_exists( 'sportspress_output_staff_selector' ) ) {
/**
* Output the staff dropdown.
*
* @access public
* @subpackage Staff/Dropdown
* @return void
*/
function sportspress_output_staff_selector() {
sp_get_template( 'staff-selector.php' );
}
}
if ( ! function_exists( 'sportspress_output_staff_photo' ) ) {
/**

View File

@@ -145,130 +145,12 @@ function sportspress_the_title( $title, $id = null ) {
if ( $number != null ):
$title = '<strong class="sp-player-number">' . $number . '</strong> ' . $title;
endif;
if ( 'yes' === get_option( 'sportspress_player_show_selector', 'yes' ) ):
$league_ids = sp_get_the_term_ids( $id, 'sp_league' );
$season_ids = sp_get_the_term_ids( $id, 'sp_season' );
$team = get_post_meta( $id, 'sp_current_team', true );
$args = array(
'post_type' => 'sp_player',
'numberposts' => 500,
'posts_per_page' => 500,
'meta_key' => 'sp_number',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'tax_query' => array(
'relation' => 'AND',
),
);
if ( $league_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_league',
'field' => 'term_id',
'terms' => $league_ids
);
endif;
if ( $season_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'term_id',
'terms' => $season_ids
);
endif;
if ( $team && apply_filters( 'sportspress_has_teams', true ) ):
$args['meta_query'] = array(
array(
'key' => 'sp_team',
'value' => $team
),
);
endif;
$players = get_posts( $args );
$options = array();
if ( $players && is_array( $players ) ):
foreach ( $players as $player ):
$name = $player->post_title;
$number = get_post_meta( $player->ID, 'sp_number', true );
if ( isset( $number ) && '' !== $number ):
$name = $number . '. ' . $name;
endif;
$options[] = '<option value="' . get_post_permalink( $player->ID ) . '" ' . selected( $player->ID, $id, false ) . '>' . $name . '</option>';
endforeach;
endif;
if ( sizeof( $options ) > 1 ):
$title .= '<select class="sp-profile-selector sp-player-selector sp-selector-redirect">' . implode( $options ) . '</select>';
endif;
endif;
elseif ( is_singular( 'sp_staff' ) ):
$staff = new SP_Staff( $id );
$role = $staff->role();
if ( $role ):
$title = '<strong class="sp-staff-role">' . $role->name . '</strong> ' . $title;
endif;
if ( 'yes' === get_option( 'sportspress_staff_show_selector', 'yes' ) ):
$league_ids = sp_get_the_term_ids( $id, 'sp_league' );
$season_ids = sp_get_the_term_ids( $id, 'sp_season' );
$team = get_post_meta( $id, 'sp_current_team', true );
$args = array(
'post_type' => 'sp_staff',
'numberposts' => 500,
'posts_per_page' => 500,
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
'relation' => 'AND',
),
);
if ( $league_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_league',
'field' => 'term_id',
'terms' => $league_ids
);
endif;
if ( $season_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'term_id',
'terms' => $season_ids
);
endif;
if ( $team && apply_filters( 'sportspress_has_teams', true ) ):
$args['meta_query'] = array(
array(
'key' => 'sp_team',
'value' => $team
),
);
endif;
$staffs = get_posts( $args );
$options = array();
if ( $staffs && is_array( $staffs ) ):
foreach ( $staffs as $staff ):
$options[] = '<option value="' . get_post_permalink( $staff->ID ) . '" ' . selected( $staff->ID, $id, false ) . '>' . $staff->post_title . '</option>';
endforeach;
endif;
if ( sizeof( $options ) > 1 ):
$title .= '<select class="sp-profile-selector sp-staff-selector sp-selector-redirect">' . implode( $options ) . '</select>';
endif;
endif;
endif;
endif;

View File

@@ -0,0 +1,80 @@
<?php
/**
* Player Dropdown
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 2.1.3
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( get_option( 'sportspress_player_show_selector', 'yes' ) === 'no' ) return;
if ( ! isset( $id ) )
$id = get_the_ID();
$league_ids = sp_get_the_term_ids( $id, 'sp_league' );
$season_ids = sp_get_the_term_ids( $id, 'sp_season' );
$team = get_post_meta( $id, 'sp_current_team', true );
$args = array(
'post_type' => 'sp_player',
'numberposts' => 500,
'posts_per_page' => 500,
'meta_key' => 'sp_number',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'tax_query' => array(
'relation' => 'AND',
),
);
if ( $league_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_league',
'field' => 'term_id',
'terms' => $league_ids
);
endif;
if ( $season_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'term_id',
'terms' => $season_ids
);
endif;
if ( $team && apply_filters( 'sportspress_has_teams', true ) ):
$args['meta_query'] = array(
array(
'key' => 'sp_team',
'value' => $team
),
);
endif;
$players = get_posts( $args );
$options = array();
if ( $players && is_array( $players ) ):
foreach ( $players as $player ):
$name = $player->post_title;
$number = get_post_meta( $player->ID, 'sp_number', true );
if ( isset( $number ) && '' !== $number ):
$name = $number . '. ' . $name;
endif;
$options[] = '<option value="' . get_post_permalink( $player->ID ) . '" ' . selected( $player->ID, $id, false ) . '>' . $name . '</option>';
endforeach;
endif;
if ( sizeof( $options ) > 1 ):
?>
<div class="sp-template sp-template-player-selector sp-template-dropdown">
<select class="sp-profile-selector sp-player-selector sp-selector-redirect">
<?php echo implode( $options ); ?>
</select>
</div>
<?php
endif;

View File

@@ -0,0 +1,74 @@
<?php
/**
* Staff Dropdown
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 2.1.3
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( get_option( 'sportspress_staff_show_selector', 'yes' ) === 'no' ) return;
if ( ! isset( $id ) )
$id = get_the_ID();
$league_ids = sp_get_the_term_ids( $id, 'sp_league' );
$season_ids = sp_get_the_term_ids( $id, 'sp_season' );
$team = get_post_meta( $id, 'sp_current_team', true );
$args = array(
'post_type' => 'sp_staff',
'numberposts' => 500,
'posts_per_page' => 500,
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
'relation' => 'AND',
),
);
if ( $league_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_league',
'field' => 'term_id',
'terms' => $league_ids
);
endif;
if ( $season_ids ):
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'term_id',
'terms' => $season_ids
);
endif;
if ( $team && apply_filters( 'sportspress_has_teams', true ) ):
$args['meta_query'] = array(
array(
'key' => 'sp_team',
'value' => $team
),
);
endif;
$staffs = get_posts( $args );
$options = array();
if ( $staffs && is_array( $staffs ) ):
foreach ( $staffs as $staff ):
$options[] = '<option value="' . get_post_permalink( $staff->ID ) . '" ' . selected( $staff->ID, $id, false ) . '>' . $staff->post_title . '</option>';
endforeach;
endif;
if ( sizeof( $options ) > 1 ):
?>
<div class="sp-template sp-template-staff-selector sp-template-dropdown">
<select class="sp-profile-selector sp-staff-selector sp-selector-redirect">
<?php echo implode( $options ); ?>
</select>
</div>
<?php
endif;