Add single event shortcode

This commit is contained in:
Brian Miyaji
2014-04-02 10:18:22 +11:00
parent cf519c4e25
commit c37ab3cdb8
10 changed files with 221 additions and 33 deletions

View File

@@ -93,6 +93,7 @@ class SP_Admin_Meta_Boxes {
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Performance_Details::output', 'sp_performance', 'normal', 'high' );
// Events
add_meta_box( 'sp_shortcodediv', __( 'Shortcode', 'sportspress' ), 'SP_Meta_Box_Event_Shortcode::output', 'sp_event', 'side', 'default' );
add_meta_box( 'sp_formatdiv', __( 'Format', 'sportspress' ), 'SP_Meta_Box_Event_Format::output', 'sp_event', 'side', 'default' );
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Event_Details::output', 'sp_event', 'side', 'default' );
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'SP_Meta_Box_Event_Teams::output', 'sp_event', 'side', 'default' );
@@ -109,6 +110,7 @@ class SP_Admin_Meta_Boxes {
add_meta_box( 'sp_descriptiondiv', __( 'Description', 'sportspress' ), 'SP_Meta_Box_Calendar_Description::output', 'sp_calendar', 'normal', 'high' );
// Teams
// add_meta_box( 'sp_shortcodediv', __( 'Shortcode', 'sportspress' ), 'SP_Meta_Box_Team_Shortcode::output', 'sp_team', 'side', 'default' );
add_meta_box( 'sp_columnssdiv', __( 'Columns', 'sportspress' ), 'SP_Meta_Box_Team_Columns::output', 'sp_team', 'normal', 'high' );
// Tables
@@ -118,6 +120,7 @@ class SP_Admin_Meta_Boxes {
add_meta_box( 'sp_descriptiondiv', __( 'Description', 'sportspress' ), 'SP_Meta_Box_Table_Description::output', 'sp_table', 'normal', 'high' );
// Players
// add_meta_box( 'sp_shortcodediv', __( 'Shortcode', 'sportspress' ), 'SP_Meta_Box_Player_Shortcode::output', 'sp_player', 'side', 'default' );
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Player_Details::output', 'sp_player', 'side', 'default' );
add_meta_box( 'sp_metricsdiv', __( 'Metrics', 'sportspress' ), 'SP_Meta_Box_Player_Metrics::output', 'sp_player', 'side', 'default' );
add_meta_box( 'sp_performancediv', __( 'Performance', 'sportspress' ), 'SP_Meta_Box_Player_Performance::output', 'sp_player', 'normal', 'high' );
@@ -128,6 +131,9 @@ class SP_Admin_Meta_Boxes {
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_List_Details::output', 'sp_list', 'side', 'default' );
add_meta_box( 'sp_datadiv', __( 'Player List', 'sportspress' ), 'SP_Meta_Box_List_Data::output', 'sp_list', 'normal', 'high' );
add_meta_box( 'sp_descriptiondiv', __( 'Description', 'sportspress' ), 'SP_Meta_Box_List_Description::output', 'sp_list', 'normal', 'high' );
// Staff
// add_meta_box( 'sp_shortcodediv', __( 'Shortcode', 'sportspress' ), 'SP_Meta_Box_Staff_Shortcode::output', 'sp_staff', 'side', 'default' );
}
/**

View File

@@ -0,0 +1,29 @@
<?php
/**
* Event Shortcode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.7.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Event_Shortcode
*/
class SP_Meta_Box_Event_Shortcode {
/**
* Output the metabox
*/
public static function output( $post ) {
?>
<p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
</p>
<p><input type="text" value="[event <?php echo $post->ID; ?>]" readonly="readonly" class="wp-ui-text-highlight code"></p>
<?php
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Player Shortcode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.7.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Player_Shortcode
*/
class SP_Meta_Box_Player_Shortcode {
/**
* Output the metabox
*/
public static function output( $post ) {
?>
<p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
</p>
<p><input type="text" value="[player <?php echo $post->ID; ?>]" readonly="readonly" class="wp-ui-text-highlight code"></p>
<?php
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Staff Shortcode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.7.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Staff_Shortcode
*/
class SP_Meta_Box_Staff_Shortcode {
/**
* Output the metabox
*/
public static function output( $post ) {
?>
<p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
</p>
<p><input type="text" value="[staff <?php echo $post->ID; ?>]" readonly="readonly" class="wp-ui-text-highlight code"></p>
<?php
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Team Shortcode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.7.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Team_Shortcode
*/
class SP_Meta_Box_Team_Shortcode {
/**
* Output the metabox
*/
public static function output( $post ) {
?>
<p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
</p>
<p><input type="text" value="[team <?php echo $post->ID; ?>]" readonly="readonly" class="wp-ui-text-highlight code"></p>
<?php
}
}

View File

@@ -16,12 +16,16 @@ class SP_Shortcodes {
public static function init() {
// Define shortcodes
$shortcodes = array(
'event' => __CLASS__ . '::event',
'countdown' => __CLASS__ . '::countdown',
'event_list' => __CLASS__ . '::event_list',
'event_calendar' => __CLASS__ . '::event_calendar',
// 'team' => __CLASS__ . '::team',
'league_table' => __CLASS__ . '::league_table',
// 'player' => __CLASS__ . '::player',
'player_list' => __CLASS__ . '::player_list',
'player_gallery' => __CLASS__ . '::player_gallery',
// 'staff' => __CLASS__ . '::staff',
);
foreach ( $shortcodes as $shortcode => $function ) {
@@ -57,6 +61,17 @@ class SP_Shortcodes {
return ob_get_clean();
}
/**
* Event shortcode.
*
* @access public
* @param mixed $atts
* @return string
*/
public static function event( $atts ) {
return self::shortcode_wrapper( array( 'SP_Shortcode_Event', 'output' ), $atts );
}
/**
* Countdown shortcode.
*
@@ -90,6 +105,17 @@ class SP_Shortcodes {
return self::shortcode_wrapper( array( 'SP_Shortcode_Event_List', 'output' ), $atts );
}
/**
* Team shortcode.
*
* @access public
* @param mixed $atts
* @return string
*/
public static function team( $atts ) {
return self::shortcode_wrapper( array( 'SP_Shortcode_Team', 'output' ), $atts );
}
/**
* League table shortcode.
*
@@ -101,6 +127,17 @@ class SP_Shortcodes {
return self::shortcode_wrapper( array( 'SP_Shortcode_League_Table', 'output' ), $atts );
}
/**
* Player shortcode.
*
* @access public
* @param mixed $atts
* @return string
*/
public static function player( $atts ) {
return self::shortcode_wrapper( array( 'SP_Shortcode_Player', 'output' ), $atts );
}
/**
* Player list shortcode.
*
@@ -122,4 +159,15 @@ class SP_Shortcodes {
public static function player_gallery( $atts ) {
return self::shortcode_wrapper( array( 'SP_Shortcode_Player_Gallery', 'output' ), $atts );
}
/**
* Staff shortcode.
*
* @access public
* @param mixed $atts
* @return string
*/
public static function staff( $atts ) {
return self::shortcode_wrapper( array( 'SP_Shortcode_Staff', 'output' ), $atts );
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* Event Shortcode
*
* @author ThemeBoy
* @category Shortcodes
* @package SportsPress/Shortcodes/Event
* @version 0.7
*/
class SP_Shortcode_Event {
/**
* Output the event shortcode.
*
* @param array $atts
*/
public static function output( $atts ) {
if ( ! isset( $atts['id'] ) && isset( $atts[0] ) && is_numeric( $atts[0] ) )
$atts['id'] = $atts[0];
sp_get_template( 'event.php', $atts );
}
}

View File

@@ -171,31 +171,8 @@ add_filter( 'the_content', 'sportspress_the_content' );
add_filter( 'get_the_content', 'sportspress_the_content' );
function sportspress_default_event_content( $content ) {
if ( is_singular( 'sp_event' ) && in_the_loop() ):
$id = get_the_ID();
// Video
$video_url = get_post_meta( $id, 'sp_video', true );
if ( $video_url ):
global $wp_embed;
echo $wp_embed->autoembed( $video_url );
endif;
// Results
sp_get_template( 'event-results.php' );
// Details
sp_get_template( 'event-details.php' );
// Venue
sp_get_template( 'event-venue.php' );
// Performance
sp_get_template( 'event-performance.php' );
// Staff
sp_get_template( 'event-staff.php' );
endif;
if ( is_singular( 'sp_event' ) && in_the_loop() )
sp_get_template( 'event.php' );
return $content;
}
@@ -258,9 +235,8 @@ function sportspress_default_table_content( $content ) {
add_filter( 'the_content', 'sportspress_default_table_content' );
function sportspress_default_player_content( $content ) {
if ( is_singular( 'sp_player' ) && in_the_loop() ):
if ( is_singular( 'sp_player' ) && in_the_loop() )
sp_get_template( 'player.php' );
endif;
return $content;
}
add_filter( 'the_content', 'sportspress_default_player_content' );

View File

@@ -0,0 +1,9 @@
<?php
if ( ! isset( $id ) )
$id = get_the_ID();
$video_url = get_post_meta( $id, 'sp_video', true );
if ( $video_url ):
global $wp_embed;
echo $wp_embed->autoembed( $video_url );
endif;

9
templates/event.php Normal file
View File

@@ -0,0 +1,9 @@
<?php
if ( ! isset( $id ) )
$id = get_the_ID();
sp_get_template( 'event-video.php', array( 'id' => $id ) );
sp_get_template( 'event-results.php', array( 'id' => $id ) );
sp_get_template( 'event-details.php', array( 'id' => $id ) );
sp_get_template( 'event-venue.php', array( 'id' => $id ) );
sp_get_template( 'event-performance.php', array( 'id' => $id ) );