Add team gallery template
This commit is contained in:
@@ -24,6 +24,10 @@
|
||||
content: "\f334";
|
||||
}
|
||||
|
||||
.post-state-format.post-format-standings:before, .post-format-icon.post-format-standings:before, a.post-state-format.format-standings:before {
|
||||
content: "\f185";
|
||||
}
|
||||
|
||||
.post-state-format.post-format-list:before, .post-format-icon.post-format-list:before, a.post-state-format.format-list:before {
|
||||
content: "\f163";
|
||||
}
|
||||
|
||||
@@ -191,6 +191,11 @@
|
||||
max-height: 2em;
|
||||
}
|
||||
|
||||
/* Team Gallery */
|
||||
.sp-template-team-gallery img {
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
/* Player List */
|
||||
.sp-player-list td {
|
||||
line-height: 2em;
|
||||
|
||||
@@ -6,6 +6,7 @@ $options = array(
|
||||
'event' => array(
|
||||
'details', 'results', 'performance'
|
||||
),
|
||||
'team' => array(),
|
||||
'player' => array(
|
||||
'details', 'statistics'
|
||||
),
|
||||
@@ -14,6 +15,7 @@ $options = array(
|
||||
$options = apply_filters( 'sportspress_shortcodes', $options );
|
||||
|
||||
foreach ( $options as $name => $group ) {
|
||||
if ( empty( $group ) ) continue;
|
||||
$shortcodes .= $name . '[' . implode( '|', $group ) . ']';
|
||||
}
|
||||
|
||||
@@ -30,7 +32,8 @@ $raw = apply_filters( 'sportspress_tinymce_strings', array(
|
||||
'performance' => __( 'Box Score', 'sportspress' ),
|
||||
'calendar' => __( 'Calendar', 'sportspress' ),
|
||||
'statistics' => __( 'Statistics', 'sportspress' ),
|
||||
'table' => __( 'League Table', 'sportspress' ),
|
||||
'team' => __( 'Team', 'sportspress' ),
|
||||
'standings' => __( 'League Table', 'sportspress' ),
|
||||
'player' => __( 'Player', 'sportspress' ),
|
||||
'list' => __( 'List', 'sportspress' ),
|
||||
'blocks' => __( 'Blocks', 'sportspress' ),
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Table Format
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta_Boxes
|
||||
* @version 2.3
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* SP_Meta_Box_Table_Format
|
||||
*/
|
||||
class SP_Meta_Box_Table_Format {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
|
||||
$the_format = get_post_meta( $post->ID, 'sp_format', true );
|
||||
?>
|
||||
<div id="post-formats-select">
|
||||
<?php foreach ( SP()->formats->table as $key => $format ): ?>
|
||||
<input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( true, ( $key == 'standings' && ! $the_format ) || $the_format == $key ); ?>> <label for="post-format-<?php echo $key; ?>" class="post-format-icon post-format-<?php echo $key; ?>"><?php echo $format; ?></label><br>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'standings' ) );
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,13 @@ class SP_Meta_Box_Table_Shortcode {
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
$the_format = get_post_meta( $post->ID, 'sp_format', true );
|
||||
if ( ! $the_format ) $the_format = 'standings';
|
||||
?>
|
||||
<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="<?php sp_shortcode_template( 'league_table', $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
|
||||
<p><input type="text" value="<?php sp_shortcode_template( 'team_' . $the_format, $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class SP_AJAX {
|
||||
'event_calendar_shortcode' => false,
|
||||
'event_list_shortcode' => false,
|
||||
'event_blocks_shortcode' => false,
|
||||
'table_table_shortcode' => false,
|
||||
'team_standings_shortcode' => false,
|
||||
'player_details_shortcode' => false,
|
||||
'player_statistics_shortcode' => false,
|
||||
'player_list_shortcode' => false,
|
||||
@@ -610,11 +610,11 @@ class SP_AJAX {
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX league_table shortcode
|
||||
* AJAX team_standings shortcode
|
||||
*/
|
||||
public function table_table_shortcode() {
|
||||
public function team_standings_shortcode() {
|
||||
?>
|
||||
<div class="wrap sp-thickbox-content" id="sp-thickbox-league_table">
|
||||
<div class="wrap sp-thickbox-content" id="sp-thickbox-team_standings">
|
||||
<p>
|
||||
<label>
|
||||
<?php _e( 'Title:', 'sportspress' ); ?>
|
||||
@@ -673,7 +673,7 @@ class SP_AJAX {
|
||||
</p>
|
||||
<?php do_action( 'sportspress_ajax_shortcode_form', 'league-table' ); ?>
|
||||
<p class="submit">
|
||||
<input type="button" class="button-primary" value="<?php _e( 'Insert Shortcode', 'sportspress' ); ?>" onclick="insertSportsPress('league_table');" />
|
||||
<input type="button" class="button-primary" value="<?php _e( 'Insert Shortcode', 'sportspress' ); ?>" onclick="insertSportsPress('team_standings');" />
|
||||
<a class="button-secondary" onclick="tb_remove();" title="<?php _e( 'Cancel', 'sportspress' ); ?>"><?php _e( 'Cancel', 'sportspress' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
@@ -971,7 +971,7 @@ class SP_AJAX {
|
||||
args.orderby = $div.find('[name=orderby]').val();
|
||||
args.order = $div.find('[name=order]').val();
|
||||
args.show_all_events_link = $div.find('[name=show_all_events_link]:checked').length;
|
||||
} else if ( 'league_table' == type ) {
|
||||
} else if ( 'team_standings' == type ) {
|
||||
args.title = $div.find('[name=title]').val();
|
||||
args.number = $div.find('[name=number]').val();
|
||||
args.columns = $div.find('[name="columns[]"]:checked').map(function() { return this.value; }).get().join(',');
|
||||
|
||||
@@ -32,6 +32,10 @@ class SP_Formats {
|
||||
'list' => __( 'List', 'sportspress' ),
|
||||
'blocks' => __( 'Blocks', 'sportspress' ),
|
||||
),
|
||||
'table' => array(
|
||||
'standings' => __( 'Standings', 'sportspress' ),
|
||||
'gallery' => __( 'Gallery', 'sportspress' ),
|
||||
),
|
||||
'list' => array(
|
||||
'list' => __( 'List', 'sportspress' ),
|
||||
'gallery' => __( 'Gallery', 'sportspress' ),
|
||||
|
||||
@@ -16,19 +16,21 @@ class SP_Shortcodes {
|
||||
public static function init() {
|
||||
// Define shortcodes
|
||||
$shortcodes = array(
|
||||
'event_results' => __CLASS__ . '::event_results',
|
||||
'event_details' => __CLASS__ . '::event_details',
|
||||
'event_performance' => __CLASS__ . '::event_performance',
|
||||
'countdown' => __CLASS__ . '::countdown',
|
||||
'player_details' => __CLASS__ . '::player_details',
|
||||
'player_statistics' => __CLASS__ . '::player_statistics',
|
||||
'staff' => __CLASS__ . '::staff',
|
||||
'event_calendar' => __CLASS__ . '::event_calendar',
|
||||
'event_list' => __CLASS__ . '::event_list',
|
||||
'event_blocks' => __CLASS__ . '::event_blocks',
|
||||
'league_table' => __CLASS__ . '::league_table',
|
||||
'player_list' => __CLASS__ . '::player_list',
|
||||
'player_gallery' => __CLASS__ . '::player_gallery',
|
||||
'event_results' => __CLASS__ . '::event_results',
|
||||
'event_details' => __CLASS__ . '::event_details',
|
||||
'event_performance' => __CLASS__ . '::event_performance',
|
||||
'countdown' => __CLASS__ . '::countdown',
|
||||
'player_details' => __CLASS__ . '::player_details',
|
||||
'player_statistics' => __CLASS__ . '::player_statistics',
|
||||
'staff' => __CLASS__ . '::staff',
|
||||
'event_calendar' => __CLASS__ . '::event_calendar',
|
||||
'event_list' => __CLASS__ . '::event_list',
|
||||
'event_blocks' => __CLASS__ . '::event_blocks',
|
||||
'league_table' => __CLASS__ . '::league_table',
|
||||
'team_standings' => __CLASS__ . '::league_table',
|
||||
'team_gallery' => __CLASS__ . '::team_gallery',
|
||||
'player_list' => __CLASS__ . '::player_list',
|
||||
'player_gallery' => __CLASS__ . '::player_gallery',
|
||||
);
|
||||
|
||||
foreach ( $shortcodes as $shortcode => $function ) {
|
||||
@@ -144,7 +146,7 @@ class SP_Shortcodes {
|
||||
}
|
||||
|
||||
/**
|
||||
* League table shortcode.
|
||||
* League table (team standings) shortcode.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $atts
|
||||
@@ -154,6 +156,17 @@ class SP_Shortcodes {
|
||||
return self::shortcode_wrapper( array( 'SP_Shortcode_League_Table', 'output' ), $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Team gallery shortcode.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $atts
|
||||
* @return string
|
||||
*/
|
||||
public static function team_gallery( $atts ) {
|
||||
return self::shortcode_wrapper( array( 'SP_Shortcode_Team_Gallery', 'output' ), $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Player details shortcode.
|
||||
*
|
||||
|
||||
24
includes/shortcodes/class-sp-shortcode-team-gallery.php
Normal file
24
includes/shortcodes/class-sp-shortcode-team-gallery.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Team Gallery Shortcode
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Shortcodes
|
||||
* @package SportsPress/Shortcodes/Team_Gallery
|
||||
* @version 2.3.2
|
||||
*/
|
||||
class SP_Shortcode_Team_Gallery {
|
||||
|
||||
/**
|
||||
* Output the team gallery 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( 'team-gallery.php', $atts );
|
||||
}
|
||||
}
|
||||
@@ -330,7 +330,12 @@ if ( ! function_exists( 'sportspress_output_league_table' ) ) {
|
||||
* @return void
|
||||
*/
|
||||
function sportspress_output_league_table() {
|
||||
sp_get_template( 'league-table.php' );
|
||||
$id = get_the_ID();
|
||||
$format = get_post_meta( $id, 'sp_format', true );
|
||||
if ( array_key_exists( $format, SP()->formats->table ) && 'standings' !== $format )
|
||||
sp_get_template( 'team-' . $format . '.php', array( 'id' => $id ) );
|
||||
else
|
||||
sp_get_template( 'league-table.php', array( 'id' => $id ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -185,6 +185,13 @@ class SportsPress_League_Tables {
|
||||
'context' => 'side',
|
||||
'priority' => 'default',
|
||||
),
|
||||
'format' => array(
|
||||
'title' => __( 'Layout', 'sportspress' ),
|
||||
'save' => 'SP_Meta_Box_Table_Format::save',
|
||||
'output' => 'SP_Meta_Box_Table_Format::output',
|
||||
'context' => 'side',
|
||||
'priority' => 'default',
|
||||
),
|
||||
'details' => array(
|
||||
'title' => __( 'Details', 'sportspress' ),
|
||||
'save' => 'SP_Meta_Box_Table_Details::save',
|
||||
@@ -209,7 +216,8 @@ class SportsPress_League_Tables {
|
||||
* @return array
|
||||
*/
|
||||
public function add_shortcodes( $shortcodes ) {
|
||||
$shortcodes['table'] = array( 'table' );
|
||||
$shortcodes['team'][] = 'standings';
|
||||
$shortcodes['team'][] = 'gallery';
|
||||
return $shortcodes;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
{ "name" : "Finish", "condition" : "else", "description" : "Finished" }
|
||||
],
|
||||
"results": [
|
||||
{ "name" : "Score", "equation" : "$strokes", "description" : "Total score" },
|
||||
{ "name" : "Par", "equation" : "$strokes - $par", "description" : "Reported score", "primary" : 1 },
|
||||
{ "name" : "FH", "description" : "Fairways hit" },
|
||||
{ "name" : "GIR", "description" : "Greens in regulation" },
|
||||
{ "name" : "Avg. Drive", "id" : "avgdrive", "description" : "Average drive (yards)" },
|
||||
{ "name" : "Putts", "description" : "Number of putts" },
|
||||
{ "name" : "Par", "equation" : "$strokes - $par", "description" : "Reported score", "primary" : 1 }
|
||||
{ "name" : "Score", "equation" : "$strokes", "description" : "Total score" }
|
||||
],
|
||||
"performance": [
|
||||
{ "name" : "1", "id" : "one", "description" : "Hole 1" },
|
||||
|
||||
@@ -23,9 +23,6 @@ if ( ! isset( $caption ) ) $caption = __( 'Results', 'sportspress' );
|
||||
// Get event result data
|
||||
$data = $event->results();
|
||||
|
||||
// Apply filters to results data
|
||||
$data = apply_filters( 'sportspress_event_results', $data, $id );
|
||||
|
||||
// The first row should be column labels
|
||||
$labels = $data[0];
|
||||
|
||||
|
||||
41
templates/team-gallery-thumbnail.php
Normal file
41
templates/team-gallery-thumbnail.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Team Gallery Thumbnail
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @package SportsPress/Templates
|
||||
* @version 2.3.2
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
$defaults = array(
|
||||
'id' => null,
|
||||
'icontag' => 'dt',
|
||||
'captiontag' => 'dd',
|
||||
'caption' => null,
|
||||
'size' => 'sportspress-crop-medium',
|
||||
'link_posts' => get_option( 'sportspress_link_teams', 'yes' ) == 'yes' ? true : false,
|
||||
);
|
||||
|
||||
extract( $defaults, EXTR_SKIP );
|
||||
|
||||
// Add caption tag if has caption
|
||||
if ( $captiontag && $caption )
|
||||
$caption = '<' . $captiontag . ' class="wp-caption-text gallery-caption small-3 columns">' . wptexturize( $caption ) . '</' . $captiontag . '>';
|
||||
|
||||
if ( $link_posts )
|
||||
$caption = '<a href="' . get_permalink( $id ) . '">' . $caption . '</a>';
|
||||
|
||||
if ( has_post_thumbnail( $id ) )
|
||||
$thumbnail = get_the_post_thumbnail( $id, $size );
|
||||
else
|
||||
$thumbnail = '<img width="150" height="150" src="http://www.gravatar.com/avatar/?s=150&d=blank&f=y" class="attachment-thumbnail wp-post-image">';
|
||||
|
||||
echo "<{$itemtag} class='gallery-item'>";
|
||||
echo "
|
||||
<{$icontag} class='gallery-icon portrait'>"
|
||||
. '<a href="' . get_permalink( $id ) . '">' . $thumbnail . '</a>'
|
||||
. "</{$icontag}>";
|
||||
echo $caption;
|
||||
echo "</{$itemtag}>";
|
||||
160
templates/team-gallery.php
Normal file
160
templates/team-gallery.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
/**
|
||||
* Team Gallery
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @package SportsPress/Templates
|
||||
* @version 2.3.2
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
$html5 = current_theme_supports( 'html5', 'gallery' );
|
||||
$defaults = array(
|
||||
'id' => get_the_ID(),
|
||||
'title' => false,
|
||||
'number' => -1,
|
||||
'orderby' => 'default',
|
||||
'order' => 'ASC',
|
||||
'itemtag' => 'dl',
|
||||
'icontag' => 'dt',
|
||||
'captiontag' => 'dd',
|
||||
'columns' => 3,
|
||||
'size' => 'sportspress-crop-medium',
|
||||
'show_all_teams_link' => false,
|
||||
'link_posts' => get_option( 'sportspress_link_teams', 'yes' ) == 'yes' ? true : false,
|
||||
);
|
||||
|
||||
extract( $defaults, EXTR_SKIP );
|
||||
|
||||
// Determine number of teams to display
|
||||
if ( -1 === $number ):
|
||||
$number = (int) get_post_meta( $id, 'sp_number', true );
|
||||
if ( $number <= 0 ) $number = -1;
|
||||
endif;
|
||||
|
||||
$itemtag = tag_escape( $itemtag );
|
||||
$captiontag = tag_escape( $captiontag );
|
||||
$icontag = tag_escape( $icontag );
|
||||
$valid_tags = wp_kses_allowed_html( 'post' );
|
||||
if ( ! isset( $valid_tags[ $itemtag ] ) )
|
||||
$itemtag = 'dl';
|
||||
if ( ! isset( $valid_tags[ $captiontag ] ) )
|
||||
$captiontag = 'dd';
|
||||
if ( ! isset( $valid_tags[ $icontag ] ) )
|
||||
$icontag = 'dt';
|
||||
|
||||
$columns = intval( $columns );
|
||||
$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
|
||||
$size = $size;
|
||||
$float = is_rtl() ? 'right' : 'left';
|
||||
|
||||
$selector = 'sp-team-gallery-' . $id;
|
||||
|
||||
$table = new SP_League_Table( $id );
|
||||
$data = $table->data();
|
||||
|
||||
// Remove the first row to leave us with the actual data
|
||||
unset( $data[0] );
|
||||
|
||||
if ( $orderby == 'default' ):
|
||||
$orderby = $table->orderby;
|
||||
$order = $table->order;
|
||||
elseif ( $orderby == 'rand' ):
|
||||
uasort( $data, 'sp_sort_random' );
|
||||
else:
|
||||
$table->priorities = array(
|
||||
array(
|
||||
'key' => $orderby,
|
||||
'order' => $order,
|
||||
),
|
||||
);
|
||||
uasort( $data, array( $table, 'sort' ) );
|
||||
endif;
|
||||
|
||||
if ( $title )
|
||||
echo '<h4 class="sp-table-caption">' . $title . '</h4>';
|
||||
|
||||
$gallery_style = $gallery_div = '';
|
||||
if ( apply_filters( 'use_default_gallery_style', ! $html5 ) )
|
||||
$gallery_style = "
|
||||
<style type='text/css'>
|
||||
#{$selector} {
|
||||
margin: auto;
|
||||
}
|
||||
#{$selector} .gallery-item {
|
||||
float: {$float};
|
||||
margin-top: 10px;
|
||||
text-align: center;
|
||||
width: {$itemwidth}%;
|
||||
}
|
||||
#{$selector} img {
|
||||
border: 2px solid #cfcfcf;
|
||||
}
|
||||
#{$selector} .gallery-caption {
|
||||
margin-left: 0;
|
||||
}
|
||||
/* see gallery_shortcode() in wp-includes/media.php */
|
||||
</style>";
|
||||
$size_class = sanitize_html_class( $size );
|
||||
$gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
|
||||
echo apply_filters( 'gallery_style', $gallery_style . "\n\t\t" );
|
||||
?>
|
||||
<?php echo $gallery_div; ?>
|
||||
<?php
|
||||
if ( intval( $number ) > 0 )
|
||||
$limit = $number;
|
||||
|
||||
$i = 0;
|
||||
|
||||
$gallery = '';
|
||||
|
||||
foreach( $data as $team_id => $row ):
|
||||
|
||||
if ( isset( $limit ) && $i >= $limit ) continue;
|
||||
|
||||
$caption = get_the_title( $team_id );
|
||||
$caption = trim( $caption );
|
||||
|
||||
ob_start();
|
||||
|
||||
sp_get_template( 'team-gallery-thumbnail.php', array(
|
||||
'id' => $team_id,
|
||||
'itemtag' => $itemtag,
|
||||
'icontag' => $icontag,
|
||||
'captiontag' => $captiontag,
|
||||
'caption' => $caption,
|
||||
'size' => $size,
|
||||
'link_posts' => $link_posts,
|
||||
) );
|
||||
|
||||
$gallery .= ob_get_clean();
|
||||
|
||||
$i++;
|
||||
|
||||
endforeach;
|
||||
|
||||
echo '<div class="sp-template sp-template-team-gallery sp-template-gallery">';
|
||||
|
||||
echo '<div class="sp-team-gallery-wrapper sp-gallery-wrapper">';
|
||||
|
||||
echo $gallery;
|
||||
|
||||
if ( ! $html5 && $columns > 0 && ++$i % $columns == 0 ) {
|
||||
echo '<br style="clear: both" />';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
if ( $show_all_teams_link ) {
|
||||
echo '<div class="sp-team-gallery-link sp-gallery-link sp-view-all-link"><a href="' . get_permalink( $id ) . '">' . __( 'View all teams', 'sportspress' ) . '</a></div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
if ( ! $html5 && $columns > 0 && ++$i % $columns == 0 ) {
|
||||
echo '<br style="clear: both" />';
|
||||
}
|
||||
|
||||
echo "</div>\n";
|
||||
?>
|
||||
Reference in New Issue
Block a user