Add events to team pages
This commit is contained in:
@@ -318,6 +318,9 @@
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
.sp-fixtures-results {
|
||||
clear: both;
|
||||
}
|
||||
.widget .sp-event-blocks .sp-event-title {
|
||||
margin: 10px;
|
||||
padding: 0;
|
||||
@@ -437,4 +440,8 @@
|
||||
display: inline-block;
|
||||
margin: 0 0.25em;
|
||||
}
|
||||
|
||||
.sp-template-logo + .sp-post-content {
|
||||
clear: left;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ class SP_Settings_Page {
|
||||
|
||||
<ul class="sp-layout sp-sortable-list ui-sortable">
|
||||
<?php foreach ( $templates as $template => $details ) {
|
||||
if ( ! is_array( $details ) ) continue;
|
||||
$option = sp_array_value( $details, 'option', 'sportspress_' . $this->template . '_show_' . $template );
|
||||
$visibility = get_option( $option, sp_array_value( $details, 'default', 'yes' ) );
|
||||
?>
|
||||
|
||||
@@ -34,6 +34,9 @@ class SP_Calendar extends SP_Custom_Post {
|
||||
/** @var int The season ID. */
|
||||
public $season;
|
||||
|
||||
/** @var int The team ID. */
|
||||
public $team;
|
||||
|
||||
/**
|
||||
* __construct function.
|
||||
*
|
||||
@@ -111,6 +114,16 @@ class SP_Calendar extends SP_Custom_Post {
|
||||
$season_ids = array( $this->season );
|
||||
endif;
|
||||
|
||||
if ( $this->team ):
|
||||
$args['meta_query'] = array(
|
||||
array(
|
||||
'key' => 'sp_team',
|
||||
'value' => array( $this->team ),
|
||||
'compare' => 'IN',
|
||||
),
|
||||
);
|
||||
endif;
|
||||
|
||||
if ( $pagenow != 'post-new.php' ):
|
||||
if ( $this->ID ):
|
||||
$leagues = get_the_terms( $this->ID, 'sp_league' );
|
||||
|
||||
@@ -394,8 +394,17 @@ class SP_Team extends SP_Custom_Post {
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC',
|
||||
'meta_key' => 'sp_team',
|
||||
'meta_value' => $this->ID,
|
||||
'meta_query' => array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'key' => 'sp_team',
|
||||
'value' => $this->ID,
|
||||
),
|
||||
array(
|
||||
'key' => 'sp_team',
|
||||
'value' => '0',
|
||||
),
|
||||
),
|
||||
);
|
||||
$lists = get_posts( $args );
|
||||
|
||||
|
||||
@@ -303,6 +303,19 @@ if ( ! function_exists( 'sportspress_output_team_lists' ) ) {
|
||||
sp_get_template( 'team-lists.php' );
|
||||
}
|
||||
}
|
||||
if ( ! function_exists( 'sportspress_output_team_events' ) ) {
|
||||
|
||||
/**
|
||||
* Output the team events.
|
||||
*
|
||||
* @access public
|
||||
* @subpackage Team/Events
|
||||
* @return void
|
||||
*/
|
||||
function sportspress_output_team_events() {
|
||||
sp_get_template( 'team-events.php' );
|
||||
}
|
||||
}
|
||||
|
||||
/** Single League Table ********************************************************/
|
||||
|
||||
|
||||
@@ -37,7 +37,9 @@ class SportsPress_Calendars {
|
||||
// Filters
|
||||
add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) );
|
||||
add_filter( 'sportspress_shortcodes', array( $this, 'add_shortcodes' ) );
|
||||
add_filter( 'sportspress_event_settings', array( $this, 'add_settings' ) );
|
||||
add_filter( 'sportspress_event_settings', array( $this, 'add_event_settings' ) );
|
||||
add_filter( 'sportspress_team_options', array( $this, 'add_team_options' ) );
|
||||
add_filter( 'sportspress_after_team_template', array( $this, 'add_team_template' ), 40 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,11 +182,11 @@ class SportsPress_Calendars {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add settings.
|
||||
* Add event settings.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_settings( $settings ) {
|
||||
public function add_event_settings( $settings ) {
|
||||
$settings = array_merge( $settings,
|
||||
array(
|
||||
array( 'title' => __( 'Event List', 'sportspress' ), 'type' => 'title', 'id' => 'event_list_options' ),
|
||||
@@ -305,7 +307,7 @@ class SportsPress_Calendars {
|
||||
'title' => __( 'Limit', 'sportspress' ),
|
||||
'id' => 'sportspress_event_blocks_rows',
|
||||
'class' => 'small-text',
|
||||
'default' => '10',
|
||||
'default' => '5',
|
||||
'desc' => __( 'events', 'sportspress' ),
|
||||
'type' => 'number',
|
||||
'custom_attributes' => array(
|
||||
@@ -321,6 +323,44 @@ class SportsPress_Calendars {
|
||||
);
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add team options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_team_options( $options ) {
|
||||
return array_merge( $options,
|
||||
array(
|
||||
array(
|
||||
'title' => __( 'Events', 'sportspress' ),
|
||||
'id' => 'sportspress_team_events_format',
|
||||
'default' => 'title',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'blocks' => __( 'Blocks', 'sportspress' ),
|
||||
'calendar' => __( 'Calendar', 'sportspress' ),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add team template.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_team_template( $templates ) {
|
||||
return array_merge( $templates, array(
|
||||
'events' => array(
|
||||
'title' => __( 'Events', 'sportspress' ),
|
||||
'option' => 'sportspress_team_show_events',
|
||||
'action' => 'sportspress_output_team_events',
|
||||
'default' => 'no',
|
||||
),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
@@ -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>';
|
||||
?>
|
||||
|
||||
@@ -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'));
|
||||
|
||||
84
templates/event-fixtures-results.php
Normal file
84
templates/event-fixtures-results.php
Normal 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>';
|
||||
@@ -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
19
templates/team-events.php
Normal 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 ) );
|
||||
@@ -10,6 +10,7 @@
|
||||
<key name="Details"/>
|
||||
<key name="Event"/>
|
||||
<key name="Event Results"/>
|
||||
<key name="Fixtures"/>
|
||||
<key name="Nationality"/>
|
||||
<key name="Outcome"/>
|
||||
<key name="Past Teams"/>
|
||||
|
||||
Reference in New Issue
Block a user