Enable player list grouping by position
This commit is contained in:
@@ -22,6 +22,7 @@ class SP_Meta_Box_List_Details {
|
|||||||
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 );
|
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 );
|
||||||
$season_id = sp_get_the_term_id( $post->ID, 'sp_season', 0 );
|
$season_id = sp_get_the_term_id( $post->ID, 'sp_season', 0 );
|
||||||
$team_id = get_post_meta( $post->ID, 'sp_team', true );
|
$team_id = get_post_meta( $post->ID, 'sp_team', true );
|
||||||
|
$grouping = get_post_meta( $post->ID, 'sp_grouping', true );
|
||||||
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
|
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
|
||||||
$order = get_post_meta( $post->ID, 'sp_order', true );
|
$order = get_post_meta( $post->ID, 'sp_order', true );
|
||||||
?>
|
?>
|
||||||
@@ -69,6 +70,13 @@ class SP_Meta_Box_List_Details {
|
|||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
</p>
|
</p>
|
||||||
|
<p><strong><?php _e( 'Grouping', 'sportspress' ); ?></strong></p>
|
||||||
|
<p>
|
||||||
|
<select name="sp_grouping">
|
||||||
|
<option value="0"><?php _e( 'None', 'sportspress' ); ?></option>
|
||||||
|
<option value="position" <?php selected( $grouping, 'position' ); ?>><?php _e( 'Position', 'sportspress' ); ?></option>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
<p><strong><?php _e( 'Sort by', 'sportspress' ); ?></strong></p>
|
<p><strong><?php _e( 'Sort by', 'sportspress' ); ?></strong></p>
|
||||||
<p>
|
<p>
|
||||||
<?php
|
<?php
|
||||||
@@ -82,9 +90,7 @@ class SP_Meta_Box_List_Details {
|
|||||||
'selected' => $orderby,
|
'selected' => $orderby,
|
||||||
'values' => 'slug',
|
'values' => 'slug',
|
||||||
);
|
);
|
||||||
if ( ! sp_dropdown_pages( $args ) ):
|
sp_dropdown_pages( $args );
|
||||||
sp_post_adder( 'sp_list', __( 'Add New', 'sportspress' ) );
|
|
||||||
endif;
|
|
||||||
?>
|
?>
|
||||||
</p>
|
</p>
|
||||||
<p><strong><?php _e( 'Sort Order', 'sportspress' ); ?></strong></p>
|
<p><strong><?php _e( 'Sort Order', 'sportspress' ); ?></strong></p>
|
||||||
@@ -110,6 +116,7 @@ class SP_Meta_Box_List_Details {
|
|||||||
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
||||||
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_league', 0 ), 'sp_league' );
|
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_league', 0 ), 'sp_league' );
|
||||||
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
|
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
|
||||||
|
update_post_meta( $post_id, 'sp_grouping', sp_array_value( $_POST, 'sp_grouping', array() ) );
|
||||||
update_post_meta( $post_id, 'sp_orderby', sp_array_value( $_POST, 'sp_orderby', array() ) );
|
update_post_meta( $post_id, 'sp_orderby', sp_array_value( $_POST, 'sp_orderby', array() ) );
|
||||||
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) );
|
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) );
|
||||||
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
|
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
|
||||||
|
|||||||
50
templates/player-gallery-thumbnail.php
Normal file
50
templates/player-gallery-thumbnail.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Player Gallery Thumbnail
|
||||||
|
*
|
||||||
|
* @author ThemeBoy
|
||||||
|
* @package SportsPress/Templates
|
||||||
|
* @version 0.8
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
|
|
||||||
|
$defaults = array(
|
||||||
|
'id' => null,
|
||||||
|
'performance' => array(),
|
||||||
|
'icontag' => 'dt',
|
||||||
|
'captiontag' => 'dd',
|
||||||
|
'caption' => null,
|
||||||
|
'size' => 'thumbnail',
|
||||||
|
'link_posts' => get_option( 'sportspress_list_link_players', 'yes' ) == 'yes' ? true : false,
|
||||||
|
);
|
||||||
|
|
||||||
|
extract( $defaults, EXTR_SKIP );
|
||||||
|
|
||||||
|
// Add player number to caption if available
|
||||||
|
$player_number = get_post_meta( $id, 'sp_number', true );
|
||||||
|
if ( $player_number )
|
||||||
|
$caption = '<strong>' . $player_number . '</strong> ' . $caption;
|
||||||
|
|
||||||
|
// 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 ( isset( $limit ) && $i >= $limit )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
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=mm&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}>";
|
||||||
@@ -12,6 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|||||||
$defaults = array(
|
$defaults = array(
|
||||||
'id' => get_the_ID(),
|
'id' => get_the_ID(),
|
||||||
'number' => -1,
|
'number' => -1,
|
||||||
|
'grouping' => null,
|
||||||
'orderby' => 'default',
|
'orderby' => 'default',
|
||||||
'order' => 'ASC',
|
'order' => 'ASC',
|
||||||
'itemtag' => 'dl',
|
'itemtag' => 'dl',
|
||||||
@@ -52,7 +53,14 @@ $labels = $data[0];
|
|||||||
// Remove the first row to leave us with the actual data
|
// Remove the first row to leave us with the actual data
|
||||||
unset( $data[0] );
|
unset( $data[0] );
|
||||||
|
|
||||||
if ( $orderby != 'default' ):
|
if ( ! $grouping || $grouping == 'default' ):
|
||||||
|
$grouping = $list->grouping;
|
||||||
|
endif;
|
||||||
|
|
||||||
|
if ( $orderby == 'default' ):
|
||||||
|
$orderby = $list->orderby;
|
||||||
|
$order = $list->order;
|
||||||
|
else:
|
||||||
$list->priorities = array(
|
$list->priorities = array(
|
||||||
array(
|
array(
|
||||||
'key' => $orderby,
|
'key' => $orderby,
|
||||||
@@ -85,54 +93,50 @@ if ( apply_filters( 'use_default_gallery_style', true ) )
|
|||||||
</style>";
|
</style>";
|
||||||
$size_class = sanitize_html_class( $size );
|
$size_class = sanitize_html_class( $size );
|
||||||
$gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
|
$gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
|
||||||
$output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
|
echo apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
if ( is_int( $number ) && $number > 0 )
|
if ( is_int( $number ) && $number > 0 )
|
||||||
$limit = $number;
|
$limit = $number;
|
||||||
|
|
||||||
foreach( $data as $player_id => $performance ):
|
if ( $grouping == 'position' ):
|
||||||
|
$groups = get_terms( 'sp_position' );
|
||||||
|
else:
|
||||||
|
$group = new stdClass();
|
||||||
|
$group->term_id = null;
|
||||||
|
$group->name = null;
|
||||||
|
$group->slug = null;
|
||||||
|
$groups = array( $group );
|
||||||
|
endif;
|
||||||
|
|
||||||
$caption = get_the_title( $player_id );
|
foreach ( $groups as $group ):
|
||||||
$caption = trim( $caption );
|
$i = 0;
|
||||||
|
|
||||||
// Add player number to caption if available
|
if ( ! empty( $group->name ) )
|
||||||
$player_number = get_post_meta( $player_id, 'sp_number', true );
|
echo '<h3 class="sp-list-group-name">' . $group->name . '</h3>';
|
||||||
if ( $player_number )
|
|
||||||
$caption = '<strong>' . $player_number . '</strong> ' . $caption;
|
|
||||||
|
|
||||||
// Add caption tag if has caption
|
foreach( $data as $player_id => $performance ): if ( empty( $group->term_id ) || has_term( $group->term_id, 'sp_position', $player_id ) ):
|
||||||
if ( $captiontag && $caption )
|
|
||||||
$caption = '<' . $captiontag . ' class="wp-caption-text gallery-caption">' . wptexturize( $caption ) . '</' . $captiontag . '>';
|
|
||||||
|
|
||||||
if ( $link_posts )
|
$caption = get_the_title( $player_id );
|
||||||
$caption = '<a href="' . get_permalink( $player_id ) . '">' . $caption . '</a>';
|
$caption = trim( $caption );
|
||||||
|
|
||||||
if ( isset( $limit ) && $i >= $limit )
|
sp_get_template( 'player-gallery-thumbnail.php', array(
|
||||||
continue;
|
'id' => $player_id,
|
||||||
|
'performance' => $performance,
|
||||||
|
'itemtag' => $itemtag,
|
||||||
|
'icontag' => $icontag,
|
||||||
|
'captiontag' => $captiontag,
|
||||||
|
'caption' => $caption,
|
||||||
|
'size' => $size,
|
||||||
|
'link_posts' => $link_posts,
|
||||||
|
) );
|
||||||
|
|
||||||
if ( has_post_thumbnail( $player_id ) ):
|
endif; endforeach;
|
||||||
$thumbnail = get_the_post_thumbnail( $player_id, $size );
|
|
||||||
|
|
||||||
$output .= "<{$itemtag} class='gallery-item'>";
|
echo '<br style="clear: both;" />';
|
||||||
$output .= "
|
|
||||||
<{$icontag} class='gallery-icon portrait'>"
|
|
||||||
. '<a href="' . get_permalink( $player_id ) . '">' . $thumbnail . '</a>'
|
|
||||||
. "</{$icontag}>";
|
|
||||||
$output .= $caption;
|
|
||||||
$output .= "</{$itemtag}>";
|
|
||||||
if ( $columns > 0 && ++$i % $columns == 0 )
|
|
||||||
$output .= '<br style="clear: both" />';
|
|
||||||
endif;
|
|
||||||
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
$output .= "
|
echo "</div>\n";
|
||||||
<br style='clear: both;' />
|
|
||||||
</div>\n";
|
|
||||||
|
|
||||||
if ( $show_all_players_link )
|
if ( $show_all_players_link )
|
||||||
$output .= '<a class="sp-player-list-link sp-view-all-link" href="' . get_permalink( $id ) . '">' . SP()->text->string('View all players') . '</a>';
|
echo '<a class="sp-player-list-link sp-view-all-link" href="' . get_permalink( $id ) . '">' . SP()->text->string('View all players') . '</a>';
|
||||||
|
|
||||||
echo apply_filters( 'sportspress_player_gallery', $output );
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ $defaults = array(
|
|||||||
'id' => get_the_ID(),
|
'id' => get_the_ID(),
|
||||||
'number' => -1,
|
'number' => -1,
|
||||||
'performance' => null,
|
'performance' => null,
|
||||||
|
'grouping' => null,
|
||||||
'orderby' => 'default',
|
'orderby' => 'default',
|
||||||
'order' => 'ASC',
|
'order' => 'ASC',
|
||||||
'show_all_players_link' => false,
|
'show_all_players_link' => false,
|
||||||
@@ -25,9 +26,6 @@ $defaults = array(
|
|||||||
|
|
||||||
extract( $defaults, EXTR_SKIP );
|
extract( $defaults, EXTR_SKIP );
|
||||||
|
|
||||||
$output = '<div class="sp-table-wrapper">' .
|
|
||||||
'<table class="sp-player-list sp-data-table' . ( $responsive ? ' sp-responsive-table' : '' ) . ( $sortable ? ' sp-sortable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>';
|
|
||||||
|
|
||||||
$list = new SP_Player_List( $id );
|
$list = new SP_Player_List( $id );
|
||||||
$data = $list->data();
|
$data = $list->data();
|
||||||
|
|
||||||
@@ -37,7 +35,14 @@ $labels = $data[0];
|
|||||||
// Remove the first row to leave us with the actual data
|
// Remove the first row to leave us with the actual data
|
||||||
unset( $data[0] );
|
unset( $data[0] );
|
||||||
|
|
||||||
if ( $orderby != 'default' ):
|
if ( ! $grouping || $grouping == 'default' ):
|
||||||
|
$grouping = $list->grouping;
|
||||||
|
endif;
|
||||||
|
|
||||||
|
if ( $orderby == 'default' ):
|
||||||
|
$orderby = $list->orderby;
|
||||||
|
$order = $list->order;
|
||||||
|
else:
|
||||||
$list->priorities = array(
|
$list->priorities = array(
|
||||||
array(
|
array(
|
||||||
'key' => $orderby,
|
'key' => $orderby,
|
||||||
@@ -47,61 +52,82 @@ if ( $orderby != 'default' ):
|
|||||||
uasort( $data, array( $list, 'sort' ) );
|
uasort( $data, array( $list, 'sort' ) );
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
if ( in_array( $orderby, array( 'number', 'name' ) ) ):
|
if ( $grouping == 'position' ):
|
||||||
$output .= '<th class="data-number">#</th>';
|
$groups = get_terms( 'sp_position' );
|
||||||
else:
|
else:
|
||||||
$output .= '<th class="data-rank">' . SP()->text->string('Rank') . '</th>';
|
$group = new stdClass();
|
||||||
|
$group->term_id = null;
|
||||||
|
$group->name = null;
|
||||||
|
$group->slug = null;
|
||||||
|
$groups = array( $group );
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
foreach( $labels as $key => $label ):
|
$output = '';
|
||||||
if ( ! is_array( $performance ) || $key == 'name' || in_array( $key, $performance ) )
|
|
||||||
$output .= '<th class="data-' . $key . '">'. $label . '</th>';
|
|
||||||
endforeach;
|
|
||||||
|
|
||||||
$output .= '</tr>' . '</thead>' . '<tbody>';
|
foreach ( $groups as $group ):
|
||||||
|
if ( ! empty( $group->name ) )
|
||||||
|
$output .= '<h3 class="sp-list-group-name">' . $group->name . '</h3>';
|
||||||
|
|
||||||
$i = 0;
|
$output .= '<div class="sp-table-wrapper">' .
|
||||||
|
'<table class="sp-player-list sp-data-table' . ( $responsive ? ' sp-responsive-table' : '' ) . ( $sortable ? ' sp-sortable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>';
|
||||||
|
|
||||||
if ( intval( $number ) > 0 )
|
if ( in_array( $orderby, array( 'number', 'name' ) ) ):
|
||||||
$limit = $number;
|
$output .= '<th class="data-number">#</th>';
|
||||||
|
|
||||||
foreach( $data as $player_id => $row ):
|
|
||||||
if ( isset( $limit ) && $i >= $limit ) continue;
|
|
||||||
|
|
||||||
$name = sp_array_value( $row, 'name', null );
|
|
||||||
if ( ! $name ) continue;
|
|
||||||
|
|
||||||
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
|
||||||
|
|
||||||
// Rank or number
|
|
||||||
if ( isset( $orderby ) && $orderby != 'number' ):
|
|
||||||
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
|
|
||||||
else:
|
else:
|
||||||
$output .= '<td class="data-number">' . sp_array_value( $row, 'number', ' ' ) . '</td>';
|
$output .= '<th class="data-rank">' . SP()->text->string('Rank') . '</th>';
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
if ( $link_posts ):
|
foreach( $labels as $key => $label ):
|
||||||
$permalink = get_post_permalink( $player_id );
|
if ( ! is_array( $performance ) || $key == 'name' || in_array( $key, $performance ) )
|
||||||
$name = '<a href="' . $permalink . '">' . $name . '</a>';
|
$output .= '<th class="data-' . $key . '">'. $label . '</th>';
|
||||||
endif;
|
|
||||||
|
|
||||||
$output .= '<td class="data-name">' . $name . '</td>';
|
|
||||||
|
|
||||||
foreach( $labels as $key => $value ):
|
|
||||||
if ( $key == 'name' )
|
|
||||||
continue;
|
|
||||||
if ( ! is_array( $performance ) || in_array( $key, $performance ) )
|
|
||||||
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '—' ) . '</td>';
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
$output .= '</tr>';
|
$output .= '</tr>' . '</thead>' . '<tbody>';
|
||||||
|
|
||||||
$i++;
|
$i = 0;
|
||||||
|
|
||||||
|
if ( intval( $number ) > 0 )
|
||||||
|
$limit = $number;
|
||||||
|
|
||||||
|
foreach( $data as $player_id => $row ): if ( empty( $group->term_id ) || has_term( $group->term_id, 'sp_position', $player_id ) ):
|
||||||
|
|
||||||
|
if ( isset( $limit ) && $i >= $limit ) continue;
|
||||||
|
|
||||||
|
$name = sp_array_value( $row, 'name', null );
|
||||||
|
if ( ! $name ) continue;
|
||||||
|
|
||||||
|
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||||
|
|
||||||
|
// Rank or number
|
||||||
|
if ( isset( $orderby ) && $orderby != 'number' ):
|
||||||
|
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
|
||||||
|
else:
|
||||||
|
$output .= '<td class="data-number">' . sp_array_value( $row, 'number', ' ' ) . '</td>';
|
||||||
|
endif;
|
||||||
|
|
||||||
|
if ( $link_posts ):
|
||||||
|
$permalink = get_post_permalink( $player_id );
|
||||||
|
$name = '<a href="' . $permalink . '">' . $name . '</a>';
|
||||||
|
endif;
|
||||||
|
|
||||||
|
$output .= '<td class="data-name">' . $name . '</td>';
|
||||||
|
|
||||||
|
foreach( $labels as $key => $value ):
|
||||||
|
if ( $key == 'name' )
|
||||||
|
continue;
|
||||||
|
if ( ! is_array( $performance ) || in_array( $key, $performance ) )
|
||||||
|
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '—' ) . '</td>';
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
$output .= '</tr>';
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
|
||||||
|
endif; endforeach;
|
||||||
|
|
||||||
|
$output .= '</tbody>' . '</table>' . '</div>';
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
$output .= '</tbody>' . '</table>' . '</div>';
|
|
||||||
|
|
||||||
if ( $show_all_players_link )
|
if ( $show_all_players_link )
|
||||||
$output .= '<a class="sp-player-list-link sp-view-all-link" href="' . get_permalink( $id ) . '">' . SP()->text->string('View all players') . '</a>';
|
$output .= '<a class="sp-player-list-link sp-view-all-link" href="' . get_permalink( $id ) . '">' . SP()->text->string('View all players') . '</a>';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user