Add events to team pages

This commit is contained in:
Brian Miyaji
2016-04-08 15:26:59 +10:00
parent 36bc9bc622
commit 35ed9962d4
12 changed files with 227 additions and 38 deletions

View File

@@ -18,17 +18,19 @@ $defaults = array(
'date_to' => 'default',
'league' => null,
'season' => null,
'team' => null,
'number' => -1,
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
'link_events' => get_option( 'sportspress_link_events', 'yes' ) == 'yes' ? true : false,
'paginated' => get_option( 'sportspress_event_blocks_paginated', 'yes' ) == 'yes' ? true : false,
'rows' => get_option( 'sportspress_event_blocks_rows', 10 ),
'rows' => get_option( 'sportspress_event_blocks_rows', 5 ),
'order' => 'default',
'show_all_events_link' => false,
'show_title' => get_option( 'sportspress_event_blocks_show_title', 'no' ) == 'yes' ? true : false,
'show_league' => get_option( 'sportspress_event_blocks_show_league', 'no' ) == 'yes' ? true : false,
'show_season' => get_option( 'sportspress_event_blocks_show_season', 'no' ) == 'yes' ? true : false,
'show_venue' => get_option( 'sportspress_event_blocks_show_venue', 'no' ) == 'yes' ? true : false,
'hide_if_empty' => false,
);
extract( $defaults, EXTR_SKIP );
@@ -46,10 +48,13 @@ if ( $league )
$calendar->league = $league;
if ( $season )
$calendar->season = $season;
if ( $team )
$calendar->team = $team;
if ( $order != 'default' )
$calendar->order = $order;
$data = $calendar->data();
$usecolumns = $calendar->columns;
if ( $hide_if_empty && empty( $data ) ) return;
if ( $show_title && false === $title && $id ):
$caption = $calendar->caption;
@@ -59,10 +64,6 @@ if ( $show_title && false === $title && $id ):
$title = get_the_title( $id );
endif;
if ( isset( $columns ) ) {
$usecolumns = $columns;
}
if ( $title )
echo '<h4 class="sp-table-caption">' . $title . '</h4>';
?>

View File

@@ -19,6 +19,7 @@ $defaults = array(
'date_to' => 'default',
'league' => null,
'season' => null,
'team' => null,
'initial' => true,
'caption_tag' => 'h4',
'show_all_events_link' => false,
@@ -26,32 +27,29 @@ $defaults = array(
extract( $defaults, EXTR_SKIP );
if ( isset( $id ) ):
$calendar = new SP_Calendar( $id );
if ( $status != 'default' )
$calendar->status = $status;
if ( $date != 'default' )
$calendar->date = $date;
if ( $date_from != 'default' )
$calendar->from = $date_from;
if ( $date_to != 'default' )
$calendar->to = $date_to;
if ( $league )
$calendar->league = $league;
if ( $season )
$calendar->season = $season;
$events = $calendar->data();
$event_ids = array();
foreach ( $events as $event ):
$event_ids[] = $event->ID;
endforeach;
if ( empty( $event_ids ) )
$in = 'AND 1 = 0'; // False logic to prevent SQL error
else
$in = 'AND ID IN (' . implode( ', ', $event_ids ) . ')';
else:
$in = '';
endif;
$calendar = new SP_Calendar( $id );
if ( $status != 'default' )
$calendar->status = $status;
if ( $date != 'default' )
$calendar->date = $date;
if ( $date_from != 'default' )
$calendar->from = $date_from;
if ( $date_to != 'default' )
$calendar->to = $date_to;
if ( $league )
$calendar->league = $league;
if ( $season )
$calendar->season = $season;
if ( $team )
$calendar->team = $team;
$events = $calendar->data();
if ( empty( $events ) ) {
$in = 'AND 1 = 0'; // False logic to prevent SQL error
} else {
$event_ids = wp_list_pluck( $events, 'ID' );
$in = 'AND ID IN (' . implode( ', ', $event_ids ) . ')';
}
// week_begins = 0 stands for Sunday
$week_begins = intval(get_option('start_of_week'));

View File

@@ -0,0 +1,84 @@
<?php
/**
* Event Blocks
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 1.9.13
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$defaults = array(
'id' => null,
'date' => 'default',
'date_from' => 'default',
'date_to' => 'default',
'league' => null,
'season' => null,
'team' => null,
'number' => -1,
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
'link_events' => get_option( 'sportspress_link_events', 'yes' ) == 'yes' ? true : false,
'paginated' => get_option( 'sportspress_event_blocks_paginated', 'yes' ) == 'yes' ? true : false,
'rows' => get_option( 'sportspress_event_blocks_rows', 5 ),
'show_league' => get_option( 'sportspress_event_blocks_show_league', 'no' ) == 'yes' ? true : false,
'show_season' => get_option( 'sportspress_event_blocks_show_season', 'no' ) == 'yes' ? true : false,
'show_venue' => get_option( 'sportspress_event_blocks_show_venue', 'no' ) == 'yes' ? true : false,
);
extract( $defaults, EXTR_SKIP );
$calendar = new SP_Calendar( $id );
if ( $date != 'default' )
$calendar->date = $date;
if ( $date_from != 'default' )
$calendar->from = $date_from;
if ( $date_to != 'default' )
$calendar->to = $date_to;
if ( $league )
$calendar->league = $league;
if ( $season )
$calendar->season = $season;
if ( $team )
$calendar->team = $team;
$args = array(
'id' => $id,
'title' => __( 'Fixtures', 'sportspress' ),
'status' => 'future',
'date' => $date,
'date_from' => $date_from,
'date_to' => $date_to,
'league' => $league,
'season' => $season,
'team' => $team,
'number' => $number,
'link_teams' => $link_teams,
'link_events' => $link_events,
'paginated' => $paginated,
'rows' => $rows,
'order' => 'ASC',
'show_all_events_link' => false,
'show_title' => true,
'show_league' => $show_league,
'show_season' => $show_season,
'show_venue' => $show_venue,
'hide_if_empty' => true,
);
echo '<div class="sp-fixtures-results">';
echo '<div class="sp-widget-align-left">';
sp_get_template( 'event-blocks.php', $args );
echo '</div>';
$args['title'] = __( 'Results', 'sportspress' );
$args['status'] = 'publish';
$args['order'] = 'DESC';
echo '<div class="sp-widget-align-right">';
sp_get_template( 'event-blocks.php', $args );
echo '</div>';
echo '</div>';

View File

@@ -18,6 +18,7 @@ $defaults = array(
'date_to' => 'default',
'league' => null,
'season' => null,
'team' => null,
'number' => -1,
'show_team_logo' => get_option( 'sportspress_event_list_show_logos', 'no' ) == 'yes' ? true : false,
'link_events' => get_option( 'sportspress_link_events', 'yes' ) == 'yes' ? true : false,
@@ -48,6 +49,8 @@ if ( $league )
$calendar->league = $league;
if ( $season )
$calendar->season = $season;
if ( $team )
$calendar->team = $team;
if ( $order != 'default' )
$calendar->order = $order;
$data = $calendar->data();

19
templates/team-events.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
/**
* Team Events
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 2.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! isset( $id ) )
$id = get_the_ID();
$format = get_option( 'sportspress_team_events_format', 'blocks' );
if ( 'calendar' === $format )
sp_get_template( 'event-calendar.php', array( 'team' => $id ) );
else
sp_get_template( 'event-fixtures-results.php', array( 'team' => $id ) );