Add inline and block option to event logos

This commit is contained in:
Brian Miyaji
2016-08-19 22:47:23 +10:00
parent 63f41473f8
commit cd68522f8d
5 changed files with 223 additions and 61 deletions

View File

@@ -10,13 +10,21 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( get_option( 'sportspress_event_show_logos', 'yes' ) === 'no' ) return;
if ( ! isset( $id ) )
$id = get_the_ID();
$teams = get_post_meta( $id, 'sp_team' );
$teams = array_filter( $teams, 'sp_filter_positive' );
if ( ! $teams ) return;
$layout = get_option( 'sportspress_event_logos_format', 'inline' );
$show_team_names = get_option( 'sportspress_event_logos_show_team_names', 'no' ) === 'yes' ? true : false;
$show_time = get_option( 'sportspress_event_logos_show_time', 'no' ) === 'yes' ? true : false;
$show_results = get_option( 'sportspress_event_logos_show_results', 'no' ) === 'yes' ? true : false;
$abbreviate_teams = get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false;
if ( ! isset( $id ) )
$id = get_the_ID();
$link_teams = get_option( 'sportspress_link_teams', 'no' ) === 'yes' ? true : false;
if ( $show_results ) {
$results = sp_get_main_results( $id );
@@ -27,61 +35,13 @@ if ( $show_results ) {
}
}
$teams = get_post_meta( $id, 'sp_team' );
$teams = array_filter( $teams, 'sp_filter_positive' );
if ( $teams ):
$team_logos = array();
$i = 0;
foreach ( $teams as $team ):
if ( ! has_post_thumbnail( $team ) ) {
$logo = '';
} else {
$logo = get_the_post_thumbnail( $team, 'sportspress-fit-icon' );
}
$alt = sizeof( $teams ) == 2 && $i % 2;
// Add team name
if ( $show_team_names ) {
if ( $alt ) {
$logo .= ' <strong class="sp-team-name">' . sp_get_team_name( $team, $abbreviate_teams ) . '</strong>';
} else {
$logo = '<strong class="sp-team-name">' . sp_get_team_name( $team, $abbreviate_teams ) . '</strong> ' . $logo;
}
}
// Add link
if ( get_option( 'sportspress_link_teams', 'no' ) == 'yes' ) $logo = '<a href="' . get_post_permalink( $team ) . '">' . $logo . '</a>';
// Add result
if ( $show_results && ! empty( $results ) ) {
$team_result = array_shift( $results );
$team_result = apply_filters( 'sportspress_event_logos_team_result', $team_result, $id, $team );
if ( $alt ) {
$logo = '<strong class="sp-team-result">' . $team_result . '</strong> ' . $logo;
} else {
$logo .= ' <strong class="sp-team-result">' . $team_result . '</strong>';
}
}
// Add logo to array
if ( '' !== $logo ) {
$team_logos[] = '<span class="sp-team-logo">' . $logo . '</span>';
$i++;
}
endforeach;
$team_logos = array_filter( $team_logos );
if ( ! empty( $team_logos ) ):
echo '<div class="sp-template sp-template-event-logos"><div class="sp-event-logos sp-event-logos-' . sizeof( $teams ) . '">';
// Assign delimiter
if ( $show_time && sizeof( $teams ) <= 2 ) {
$delimiter = '<strong class="sp-event-logos-time sp-team-result">' . get_the_time( get_option('time_format'), $id ) . '</strong>';
} else {
$delimiter = get_option( 'sportspress_event_teams_delimiter', 'vs' );
}
echo implode( ' ' . $delimiter . ' ', $team_logos );
echo '</div></div>';
endif;
endif;
sp_get_template( 'event-logos-' . $layout . '.php', array(
'id' => $id,
'teams' => $teams,
'results' => $results,
'show_team_names' => $show_team_names,
'show_time' => $show_time,
'show_results' => $show_results,
'abbreviate_teams' => $abbreviate_teams,
'link_teams' => $link_teams,
) );