Merge pull request #239 from ThemeBoy/feature-responsive
Add responsive tables
This commit is contained in:
@@ -507,3 +507,76 @@ function sportspress_output_br_tag() {
|
||||
<br>
|
||||
<?php
|
||||
}
|
||||
if ( ! function_exists( 'sportspress_responsive_tables_css' ) ) {
|
||||
|
||||
/**
|
||||
* Output the inlince css code for responsive tables.
|
||||
*
|
||||
* @access public
|
||||
* @subpackage Responsive
|
||||
* @return void
|
||||
*/
|
||||
function sportspress_responsive_tables_css( $identity ) {
|
||||
$custom_css = '/*
|
||||
Max width before this PARTICULAR table gets nasty
|
||||
This query will take effect for any screen smaller than 760px
|
||||
and also iPads specifically.
|
||||
*/
|
||||
@media
|
||||
only screen and (max-width: 800px) {
|
||||
|
||||
/* Force table to not be like tables anymore */
|
||||
table.'.$identity.', table.'.$identity.' thead, table.'.$identity.' tfoot, table.'.$identity.' tbody, table.'.$identity.' th, table.'.$identity.' td, table.'.$identity.' tr {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Hide table headers (but not display: none;, for accessibility) */
|
||||
table.'.$identity.' thead tr {
|
||||
position: absolute;
|
||||
top: -9999px;
|
||||
left: -9999px;
|
||||
}
|
||||
|
||||
/* Add subtle border to table rows */
|
||||
table.'.$identity.' tbody tr {
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.sp-data-table .data-number, .sp-data-table .data-rank {
|
||||
width: auto !important;
|
||||
}
|
||||
|
||||
.sp-data-table th,
|
||||
.sp-data-table td {
|
||||
text-align: center !important;
|
||||
}
|
||||
|
||||
table.'.$identity.' td {
|
||||
/* Behave like a "row" */
|
||||
border: none;
|
||||
position: relative;
|
||||
padding-left: 50%;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
table.'.$identity.' td:before {
|
||||
/* Now like a table header */
|
||||
position: absolute;
|
||||
/* Label the data */
|
||||
content: attr(data-label);
|
||||
/* Top/left values mimic padding */
|
||||
top: 6px;
|
||||
left: 6px;
|
||||
width: 45%;
|
||||
padding-right: 10px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
';
|
||||
|
||||
$dummystyle = 'sportspress-style-inline-'.$identity;
|
||||
wp_register_style( $dummystyle, false );
|
||||
wp_enqueue_style( $dummystyle );
|
||||
wp_add_inline_style( $dummystyle, $custom_css );
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ $defaults = array(
|
||||
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
|
||||
'link_venues' => get_option( 'sportspress_link_venues', 'yes' ) == 'yes' ? true : false,
|
||||
'abbreviate_teams' => get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false,
|
||||
'responsive' => get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false,
|
||||
'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false,
|
||||
'scrollable' => get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false,
|
||||
'paginated' => get_option( 'sportspress_event_list_paginated', 'yes' ) == 'yes' ? true : false,
|
||||
@@ -91,13 +92,16 @@ if ( $show_title && false === $title && $id ):
|
||||
else
|
||||
$title = get_the_title( $id );
|
||||
endif;
|
||||
$labels = array();
|
||||
//Create a unique identifier based on the current time in microseconds
|
||||
$identifier = uniqid( 'eventlist_' );
|
||||
?>
|
||||
<div class="sp-template sp-template-event-list">
|
||||
<?php if ( $title ) { ?>
|
||||
<h4 class="sp-table-caption"><?php echo $title; ?></h4>
|
||||
<?php } ?>
|
||||
<div class="sp-table-wrapper">
|
||||
<table class="sp-event-list sp-event-list-format-<?php echo $title_format; ?> sp-data-table<?php if ( $paginated ) { ?> sp-paginated-table<?php } if ( $sortable ) { ?> sp-sortable-table<?php } if ( $scrollable ) { ?> sp-scrollable-table<?php } ?>" data-sp-rows="<?php echo $rows; ?>">
|
||||
<table class="sp-event-list sp-event-list-format-<?php echo $title_format; ?> sp-data-table<?php if ( $paginated ) { ?> sp-paginated-table<?php } if ( $sortable ) { ?> sp-sortable-table<?php } if ( $responsive ) { echo ' sp-responsive-table '.$identifier; } if ( $scrollable ) { ?> sp-scrollable-table <?php } ?>" data-sp-rows="<?php echo $rows; ?>">
|
||||
<thead>
|
||||
<tr>
|
||||
<?php
|
||||
@@ -111,6 +115,7 @@ endif;
|
||||
|
||||
if ( 'combined' == $time_format && sp_column_active( $usecolumns, 'time' ) ) {
|
||||
echo '<th class="data-time">' . __( 'Time/Results', 'sportspress' ) . '</th>';
|
||||
$labels[] = __( 'Time/Results', 'sportspress' );
|
||||
} elseif ( in_array( $time_format, array( 'separate', 'results' ) ) && sp_column_active( $usecolumns, 'results' ) ) {
|
||||
echo '<th class="data-results">' . __( 'Results', 'sportspress' ) . '</th>';
|
||||
}
|
||||
@@ -125,10 +130,11 @@ endif;
|
||||
break;
|
||||
default:
|
||||
if ( sp_column_active( $usecolumns, 'event' ) ) {
|
||||
if ( $title_format == 'teams' )
|
||||
if ( $title_format == 'teams' ){
|
||||
echo '<th class="data-teams">' . __( 'Teams', 'sportspress' ) . '</th>';
|
||||
else
|
||||
} else {
|
||||
echo '<th class="data-event">' . __( 'Event', 'sportspress' ) . '</th>';
|
||||
}
|
||||
}
|
||||
|
||||
switch ( $time_format ) {
|
||||
@@ -241,17 +247,17 @@ endif;
|
||||
|
||||
if ( $link_events ) $date_html = '<a href="' . get_post_permalink( $event->ID, false, true ) . '" itemprop="url">' . $date_html . '</a>';
|
||||
|
||||
echo '<td class="data-date" itemprop="startDate" content="' . mysql2date( 'Y-m-d\TH:iP', $event->post_date ) . '">' . $date_html . '</td>';
|
||||
echo '<td class="data-date" itemprop="startDate" content="' . mysql2date( 'Y-m-d\TH:iP', $event->post_date ) . '" data-label="'.__( 'Date', 'sportspress' ).'">' . $date_html . '</td>';
|
||||
|
||||
switch ( $title_format ) {
|
||||
case 'homeaway':
|
||||
if ( sp_column_active( $usecolumns, 'event' ) ) {
|
||||
$team = array_shift( $teams_array );
|
||||
echo '<td class="data-home' . $team_class . '" itemprop="competitor" itemscope itemtype="http://schema.org/SportsTeam">' . $team . '</td>';
|
||||
echo '<td class="data-home' . $team_class . '" itemprop="competitor" itemscope itemtype="http://schema.org/SportsTeam" data-label="'.__( 'Home', 'sportspress' ).'">' . $team . '</td>';
|
||||
}
|
||||
|
||||
if ( 'combined' == $time_format && sp_column_active( $usecolumns, 'time' ) ) {
|
||||
echo '<td class="data-time">';
|
||||
echo '<td class="data-time" data-label="'.__( 'Time/Results', 'sportspress' ).'">';
|
||||
if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '" itemprop="url">';
|
||||
if ( ! empty( $main_results ) ):
|
||||
echo implode( ' - ', $main_results );
|
||||
@@ -261,7 +267,7 @@ endif;
|
||||
if ( $link_events ) echo '</a>';
|
||||
echo '</td>';
|
||||
} elseif ( in_array( $time_format, array( 'separate', 'results' ) ) && sp_column_active( $usecolumns, 'results' ) ) {
|
||||
echo '<td class="data-results">';
|
||||
echo '<td class="data-results" data-label="'.__( 'Results', 'sportspress' ).'">';
|
||||
if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '" itemprop="url">';
|
||||
if ( ! empty( $main_results ) ):
|
||||
echo implode( ' - ', $main_results );
|
||||
@@ -274,11 +280,11 @@ endif;
|
||||
|
||||
if ( sp_column_active( $usecolumns, 'event' ) ) {
|
||||
$team = array_shift( $teams_array );
|
||||
echo '<td class="data-away' . $team_class . '" itemprop="competitor" itemscope itemtype="http://schema.org/SportsTeam">' . $team . '</td>';
|
||||
echo '<td class="data-away' . $team_class . '" itemprop="competitor" itemscope itemtype="http://schema.org/SportsTeam" data-label="'.__( 'Away', 'sportspress' ).'">' . $team . '</td>';
|
||||
}
|
||||
|
||||
if ( in_array( $time_format, array( 'separate', 'time' ) ) && sp_column_active( $usecolumns, 'time' ) ) {
|
||||
echo '<td class="data-time">';
|
||||
echo '<td class="data-time" data-label="'.__( 'Time', 'sportspress' ).'">';
|
||||
if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '" itemprop="url">';
|
||||
echo '<date> ' . get_post_time( 'H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', sp_get_time( $event ), $event->ID );
|
||||
if ( $link_events ) echo '</a>';
|
||||
@@ -288,25 +294,25 @@ endif;
|
||||
default:
|
||||
if ( sp_column_active( $usecolumns, 'event' ) ) {
|
||||
if ( $title_format == 'teams' ) {
|
||||
echo '<td class="data-event data-teams">' . $teams_output . '</td>';
|
||||
echo '<td class="data-event data-teams" data-label="'.__( 'Teams', 'sportspress' ).'">' . $teams_output . '</td>';
|
||||
} else {
|
||||
$title_html = implode( ' ', $team_logos ) . ' ' . $event->post_title;
|
||||
if ( $link_events ) $title_html = '<a href="' . get_post_permalink( $event->ID, false, true ) . '" itemprop="url">' . $title_html . '</a>';
|
||||
echo '<td class="data-event">' . $title_html . '</td>';
|
||||
echo '<td class="data-event" data-label="'.__( 'Event', 'sportspress' ).'">' . $title_html . '</td>';
|
||||
}
|
||||
}
|
||||
|
||||
switch ( $time_format ) {
|
||||
case 'separate':
|
||||
if ( sp_column_active( $usecolumns, 'time' ) ) {
|
||||
echo '<td class="data-time">';
|
||||
echo '<td class="data-time" data-label="'.__( 'Time', 'sportspress' ).'">';
|
||||
if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '" itemprop="url">';
|
||||
echo '<date> ' . get_post_time( 'H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', sp_get_time( $event ), $event->ID );
|
||||
if ( $link_events ) echo '</a>';
|
||||
echo '</td>';
|
||||
}
|
||||
if ( sp_column_active( $usecolumns, 'results' ) ) {
|
||||
echo '<td class="data-results">';
|
||||
echo '<td class="data-results" data-label="'.__( 'Results', 'sportspress' ).'">';
|
||||
if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '" itemprop="url">';
|
||||
if ( ! empty( $main_results ) ):
|
||||
echo implode( ' - ', $main_results );
|
||||
@@ -319,7 +325,7 @@ endif;
|
||||
break;
|
||||
case 'time':
|
||||
if ( sp_column_active( $usecolumns, 'time' ) ) {
|
||||
echo '<td class="data-time">';
|
||||
echo '<td class="data-time" data-label="'.__( 'Time', 'sportspress' ).'">';
|
||||
if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '" itemprop="url">';
|
||||
echo '<date> ' . get_post_time( 'H:i:s', false, $event ) . '</date>' . apply_filters( 'sportspress_event_time', sp_get_time( $event ), $event->ID );
|
||||
if ( $link_events ) echo '</a>';
|
||||
@@ -328,7 +334,7 @@ endif;
|
||||
break;
|
||||
case 'results':
|
||||
if ( sp_column_active( $usecolumns, 'results' ) ) {
|
||||
echo '<td class="data-results">';
|
||||
echo '<td class="data-results" data-label="'.__( 'Results', 'sportspress' ).'">';
|
||||
if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '" itemprop="url">';
|
||||
if ( ! empty( $main_results ) ):
|
||||
echo implode( ' - ', $main_results );
|
||||
@@ -341,7 +347,7 @@ endif;
|
||||
break;
|
||||
default:
|
||||
if ( sp_column_active( $usecolumns, 'time' ) ) {
|
||||
echo '<td class="data-time">';
|
||||
echo '<td class="data-time" data-label="'.__( 'Time/Results', 'sportspress' ).'">';
|
||||
if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '" itemprop="url">';
|
||||
if ( ! empty( $main_results ) ):
|
||||
echo implode( ' - ', $main_results );
|
||||
@@ -355,7 +361,7 @@ endif;
|
||||
}
|
||||
|
||||
if ( sp_column_active( $usecolumns, 'league' ) ):
|
||||
echo '<td class="data-league">';
|
||||
echo '<td class="data-league" data-label="'.__( 'League', 'sportspress' ).'">';
|
||||
$leagues = get_the_terms( $event->ID, 'sp_league' );
|
||||
if ( $leagues ): foreach ( $leagues as $league ):
|
||||
echo $league->name;
|
||||
@@ -364,7 +370,7 @@ endif;
|
||||
endif;
|
||||
|
||||
if ( sp_column_active( $usecolumns, 'season' ) ):
|
||||
echo '<td class="data-season">';
|
||||
echo '<td class="data-season" data-label="'.__( 'Season', 'sportspress' ).'">';
|
||||
$seasons = get_the_terms( $event->ID, 'sp_season' );
|
||||
if ( $seasons ): foreach ( $seasons as $season ):
|
||||
echo $season->name;
|
||||
@@ -373,7 +379,7 @@ endif;
|
||||
endif;
|
||||
|
||||
if ( sp_column_active( $usecolumns, 'venue' ) ):
|
||||
echo '<td class="data-venue">';
|
||||
echo '<td class="data-venue" data-label="'.__( 'Venue', 'sportspress' ).'">';
|
||||
if ( $link_venues ):
|
||||
the_terms( $event->ID, 'sp_venue' );
|
||||
else:
|
||||
@@ -386,7 +392,7 @@ endif;
|
||||
endif;
|
||||
|
||||
if ( sp_column_active( $usecolumns, 'article' ) ):
|
||||
echo '<td class="data-article">';
|
||||
echo '<td class="data-article" data-label="'.__( 'Article', 'sportspress' ).'">';
|
||||
if ( $link_events ) echo '<a href="' . get_post_permalink( $event->ID, false, true ) . '" itemprop="url">';
|
||||
|
||||
if ( $video ):
|
||||
@@ -407,7 +413,7 @@ endif;
|
||||
endif;
|
||||
|
||||
if ( sp_column_active( $usecolumns, 'day' ) ):
|
||||
echo '<td class="data-day">';
|
||||
echo '<td class="data-day" data-label="'.__( 'Match Day', 'sportspress' ).'">';
|
||||
$day = get_post_meta( $event->ID, 'sp_day', true );
|
||||
if ( '' == $day ) {
|
||||
echo '-';
|
||||
@@ -428,7 +434,12 @@ endif;
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
if ( $id && $show_all_events_link )
|
||||
// If responsive tables are enabled then load the inline css code
|
||||
if ( $responsive ){
|
||||
sportspress_responsive_tables_css( $identifier );
|
||||
}
|
||||
if ( $id && $show_all_events_link ) {
|
||||
echo '<div class="sp-calendar-link sp-view-all-link"><a href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a></div>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
@@ -20,13 +20,21 @@ if ( ! isset( $class ) ) $class = null;
|
||||
// Initialize arrays
|
||||
if ( ! isset( $lineups ) ) $lineups = array();
|
||||
if ( ! isset( $subs ) ) $subs = array();
|
||||
|
||||
$responsive = get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false;
|
||||
//Create a unique identifier based on the current time in microseconds
|
||||
$identifier = uniqid( 'performance_' );
|
||||
// If responsive tables are enabled then load the inline css code
|
||||
if ( true == $responsive && $mode == 'values' ){
|
||||
sportspress_responsive_tables_css( $identifier );
|
||||
}
|
||||
?>
|
||||
<div class="sp-template sp-template-event-performance sp-template-event-performance-<?php echo $mode; ?><?php if ( isset( $class ) ) { echo ' ' . $class; } ?>">
|
||||
<?php if ( $caption ): ?>
|
||||
<h4 class="sp-table-caption"><?php echo $caption; ?></h4>
|
||||
<?php endif; ?>
|
||||
<div class="sp-table-wrapper">
|
||||
<table class="sp-event-performance sp-data-table<?php if ( $mode == 'values' ) { ?><?php if ( $scrollable ) { ?> sp-scrollable-table<?php } ?><?php if ( $sortable ) { ?> sp-sortable-table<?php } ?><?php } ?>">
|
||||
<table class="sp-event-performance sp-data-table<?php if ( $mode == 'values' ) { ?><?php if ( $scrollable ) { ?> sp-scrollable-table<?php }if ( $responsive ) { echo ' sp-responsive-table '.$identifier; } if ( $sortable ) { ?> sp-sortable-table<?php } ?><?php } ?>">
|
||||
<thead>
|
||||
<tr>
|
||||
<?php if ( $mode == 'values' ): ?>
|
||||
@@ -37,8 +45,10 @@ if ( ! isset( $subs ) ) $subs = array();
|
||||
<th class="data-name">
|
||||
<?php if ( isset( $section_label ) ) { ?>
|
||||
<?php echo $section_label; ?>
|
||||
<?php $player_title = $section_label; ?>
|
||||
<?php } else { ?>
|
||||
<?php _e( 'Player', 'sportspress' ); ?>
|
||||
<?php $player_title = __( 'Player', 'sportspress' ); ?>
|
||||
<?php } ?>
|
||||
</th>
|
||||
<?php endif; ?>
|
||||
@@ -84,7 +94,7 @@ if ( ! isset( $subs ) ) $subs = array();
|
||||
$number = sp_array_value( $row, 'number', ' ' );
|
||||
|
||||
// Player number
|
||||
echo '<td class="data-number">' . $number . '</td>';
|
||||
echo '<td class="data-number" data-label="#">' . $number . '</td>';
|
||||
}
|
||||
|
||||
if ( $link_posts ):
|
||||
@@ -167,7 +177,7 @@ if ( ! isset( $subs ) ) $subs = array();
|
||||
endif;
|
||||
|
||||
if ( $mode == 'values' ):
|
||||
$content .= '<td class="data-' . $key . '">' . $value . '</td>';
|
||||
$content .= '<td class="data-' . $key . '" data-label="'.$labels[$key].'">' . $value . '</td>';
|
||||
elseif ( intval( $value ) && $mode == 'icons' ):
|
||||
$performance_id = sp_array_value( $performance_ids, $key, null );
|
||||
$icons = '';
|
||||
@@ -182,7 +192,7 @@ if ( ! isset( $subs ) ) $subs = array();
|
||||
$name .= ' <small class="sp-player-position">' . $position . '</small>';
|
||||
endif;
|
||||
|
||||
echo '<td class="data-name">' . $name . '</td>';
|
||||
echo '<td class="data-name" data-label="'.$player_title.'">' . $name . '</td>';
|
||||
|
||||
if ( $mode == 'icons' ):
|
||||
echo '<td class="sp-performance-icons">' . $content . '</td>';
|
||||
@@ -208,10 +218,10 @@ if ( ! isset( $subs ) ) $subs = array();
|
||||
<?php
|
||||
if ( $show_players ):
|
||||
if ( apply_filters( 'sportspress_event_performance_show_numbers', $show_numbers, $section ) ) {
|
||||
echo '<td class="data-number"> </td>';
|
||||
echo '<td class="data-number" data-label=" "> </td>';
|
||||
}
|
||||
if ( $mode == 'values' ):
|
||||
echo '<td class="data-name">' . __( 'Total', 'sportspress' ) . '</td>';
|
||||
echo '<td class="data-name" data-label=" ">' . __( 'Total', 'sportspress' ) . '</td>';
|
||||
endif;
|
||||
endif;
|
||||
|
||||
@@ -235,7 +245,11 @@ if ( ! isset( $subs ) ) $subs = array();
|
||||
endif;
|
||||
|
||||
if ( $mode == 'values' ):
|
||||
echo '<td class="data-' . $key . '">' . $value . '</td>';
|
||||
if ($key == 'position'){
|
||||
echo '<td class="data-' . $key . '" data-label=" ">' . $value . '</td>';
|
||||
}else{
|
||||
echo '<td class="data-' . $key . '" data-label="'.$labels[$key].'">' . $value . '</td>';
|
||||
}
|
||||
elseif ( intval( $value ) && $mode == 'icons' ):
|
||||
$performance_id = sp_array_value( $performance_ids, $key, null );
|
||||
$icons = '';
|
||||
@@ -256,4 +270,4 @@ if ( ! isset( $subs ) ) $subs = array();
|
||||
</div>
|
||||
|
||||
<?php do_action( 'sportspress_after_event_performance_table', $data, $lineups, $subs, $class ); ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -19,6 +19,7 @@ $defaults = array(
|
||||
'show_title' => get_option( 'sportspress_table_show_title', 'yes' ) == 'yes' ? true : false,
|
||||
'show_team_logo' => get_option( 'sportspress_table_show_logos', 'yes' ) == 'yes' ? true : false,
|
||||
'link_posts' => null,
|
||||
'responsive' => get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false,
|
||||
'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false,
|
||||
'scrollable' => get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false,
|
||||
'paginated' => get_option( 'sportspress_table_paginated', 'yes' ) == 'yes' ? true : false,
|
||||
@@ -47,6 +48,9 @@ if ( $show_title && false === $title && $id ):
|
||||
$title = get_the_title( $id );
|
||||
endif;
|
||||
|
||||
//Create a unique identifier based on the current time in microseconds
|
||||
$identifier = uniqid( 'table_' );
|
||||
|
||||
$output = '';
|
||||
|
||||
if ( $title )
|
||||
@@ -54,13 +58,16 @@ if ( $title )
|
||||
|
||||
$output .= '<div class="sp-table-wrapper">';
|
||||
|
||||
$output .= '<table class="sp-league-table sp-data-table' . ( $sortable ? ' sp-sortable-table' : '' ) . ( $scrollable ? ' sp-scrollable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>';
|
||||
$output .= '<table class="sp-league-table sp-data-table' . ( $sortable ? ' sp-sortable-table' : '' ) . ( $responsive ? ' sp-responsive-table '.$identifier : '' ). ( $scrollable ? ' sp-scrollable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>';
|
||||
|
||||
$data = $table->data();
|
||||
|
||||
// The first row should be column labels
|
||||
$labels = $data[0];
|
||||
|
||||
// If responsive tables are enabled then load the inline css code
|
||||
if ( true == $responsive ){
|
||||
sportspress_responsive_tables_css( $identifier );
|
||||
}
|
||||
// Remove the first row to leave us with the actual data
|
||||
unset( $data[0] );
|
||||
|
||||
@@ -132,7 +139,7 @@ foreach ( $data as $team_id => $row ):
|
||||
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . $tr_class . ' sp-row-no-' . $i . '">';
|
||||
|
||||
// Rank
|
||||
$output .= '<td class="data-rank' . $td_class . '">' . sp_array_value( $row, 'pos' ) . '</td>';
|
||||
$output .= '<td class="data-rank' . $td_class . '" data-label="'.$labels['pos'].'">' . sp_array_value( $row, 'pos' ) . '</td>';
|
||||
|
||||
$name_class = '';
|
||||
|
||||
@@ -149,13 +156,13 @@ foreach ( $data as $team_id => $row ):
|
||||
$name = '<a href="' . $permalink . '">' . $name . '</a>';
|
||||
endif;
|
||||
|
||||
$output .= '<td class="data-name' . $name_class . $td_class . '">' . $name . '</td>';
|
||||
$output .= '<td class="data-name' . $name_class . $td_class . '" data-label="'.$labels['name'].'">' . $name . '</td>';
|
||||
|
||||
foreach( $labels as $key => $value ):
|
||||
if ( in_array( $key, array( 'pos', 'name' ) ) )
|
||||
continue;
|
||||
if ( ! is_array( $columns ) || in_array( $key, $columns ) )
|
||||
$output .= '<td class="data-' . $key . $td_class . '">' . sp_array_value( $row, $key, '—' ) . '</td>';
|
||||
$output .= '<td class="data-' . $key . $td_class . '" data-label="'.$labels[$key].'">' . sp_array_value( $row, $key, '—' ) . '</td>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr>';
|
||||
@@ -171,7 +178,6 @@ $output .= '</div>';
|
||||
|
||||
if ( $show_full_table_link )
|
||||
$output .= '<div class="sp-league-table-link sp-view-all-link"><a href="' . get_permalink( $id ) . '">' . __( 'View full table', 'sportspress' ) . '</a></div>';
|
||||
|
||||
?>
|
||||
<div class="sp-template sp-template-league-table">
|
||||
<?php echo $output; ?>
|
||||
|
||||
@@ -25,6 +25,7 @@ $defaults = array(
|
||||
'link_posts' => get_option( 'sportspress_link_players', 'yes' ) == 'yes' ? true : false,
|
||||
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
|
||||
'abbreviate_teams' => get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false,
|
||||
'responsive' => get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false,
|
||||
'sortable' => get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false,
|
||||
'scrollable' => get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false,
|
||||
'paginated' => get_option( 'sportspress_list_paginated', 'yes' ) == 'yes' ? true : false,
|
||||
@@ -56,6 +57,12 @@ $data = $list->data();
|
||||
// The first row should be column labels
|
||||
$labels = $data[0];
|
||||
|
||||
//Create a unique identifier based on the current time in microseconds
|
||||
$identifier = uniqid( 'playerlist_' );
|
||||
// If responsive tables are enabled then load the inline css code
|
||||
if ( true == $responsive ){
|
||||
sportspress_responsive_tables_css( $identifier );
|
||||
}
|
||||
// Remove the first row to leave us with the actual data
|
||||
unset( $data[0] );
|
||||
|
||||
@@ -130,9 +137,9 @@ foreach ( $groups as $group ):
|
||||
// Rank or number
|
||||
if ( ! is_array( $labels ) || array_key_exists( 'number', $labels ) ):
|
||||
if ( isset( $orderby ) && $orderby != 'number' ):
|
||||
$tbody .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
|
||||
$tbody .= '<td class="data-rank" data-label="'.$labels['number'].'">' . ( $i + 1 ) . '</td>';
|
||||
else:
|
||||
$tbody .= '<td class="data-number">' . sp_array_value( $row, 'number', ' ' ) . '</td>';
|
||||
$tbody .= '<td class="data-number" data-label="'.$labels['number'].'">' . sp_array_value( $row, 'number', ' ' ) . '</td>';
|
||||
endif;
|
||||
endif;
|
||||
|
||||
@@ -162,7 +169,7 @@ foreach ( $groups as $group ):
|
||||
$name = '<a href="' . $permalink . '">' . $name . '</a>';
|
||||
endif;
|
||||
|
||||
$tbody .= '<td class="data-name' . $name_class . '">' . $name . '</td>';
|
||||
$tbody .= '<td class="data-name' . $name_class . '" data-label="'.$labels['name'].'">' . $name . '</td>';
|
||||
|
||||
if ( array_key_exists( 'team', $labels ) ):
|
||||
$team = sp_array_value( $row, 'team', get_post_meta( $id, 'sp_team', true ) );
|
||||
@@ -170,7 +177,7 @@ foreach ( $groups as $group ):
|
||||
if ( $link_teams && false !== get_post_status( $team ) ):
|
||||
$team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
|
||||
endif;
|
||||
$tbody .= '<td class="data-team">' . $team_name . '</td>';
|
||||
$tbody .= '<td class="data-team" data-label="'.$labels['team'].'">' . $team_name . '</td>';
|
||||
endif;
|
||||
|
||||
if ( array_key_exists( 'position', $labels ) ):
|
||||
@@ -181,14 +188,14 @@ foreach ( $groups as $group ):
|
||||
$position_term = get_term_by( 'id', $position, 'sp_position', ARRAY_A );
|
||||
$positions = sp_array_value( $position_term, 'name', '—' );
|
||||
endif;
|
||||
$tbody .= '<td class="data-position">' . $positions . '</td>';
|
||||
$tbody .= '<td class="data-position" data-label="'.$labels['position'].'">' . $positions . '</td>';
|
||||
endif;
|
||||
|
||||
foreach( $labels as $key => $value ):
|
||||
if ( in_array( $key, array( 'number', 'name', 'team', 'position' ) ) )
|
||||
continue;
|
||||
if ( ! is_array( $columns ) || in_array( $key, $columns ) )
|
||||
$tbody .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '—' ) . '</td>';
|
||||
$tbody .= '<td class="data-' . $key . '" data-label="'.$labels[$key].'">' . sp_array_value( $row, $key, '—' ) . '</td>';
|
||||
endforeach;
|
||||
|
||||
$tbody .= '</tr>';
|
||||
@@ -207,7 +214,7 @@ foreach ( $groups as $group ):
|
||||
endif;
|
||||
|
||||
$output .= '<div class="sp-table-wrapper">' .
|
||||
'<table class="sp-player-list sp-data-table' . ( $sortable ? ' sp-sortable-table' : '' ) . ( $scrollable ? ' sp-scrollable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>';
|
||||
'<table class="sp-player-list sp-data-table' . ( $sortable ? ' sp-sortable-table' : '' ). ( $responsive ? ' sp-responsive-table '.$identifier : '' ) . ( $scrollable ? ' sp-scrollable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>';
|
||||
|
||||
if ( ! is_array( $labels ) || array_key_exists( 'number', $labels ) ):
|
||||
if ( in_array( $orderby, array( 'number', 'name' ) ) ):
|
||||
|
||||
Reference in New Issue
Block a user