Add more front end glory
This commit is contained in:
276
functions.php
276
functions.php
@@ -2,100 +2,53 @@
|
||||
if ( !function_exists( 'sportspress_event_details' ) ) {
|
||||
function sportspress_event_details( $id ) {
|
||||
|
||||
$date = get_the_time( get_option('date_format'), $id );
|
||||
$time = get_the_time( get_option('time_format'), $id );
|
||||
$leagues = get_the_terms( $id, 'sp_league' );
|
||||
$seasons = get_the_terms( $id, 'sp_season' );
|
||||
|
||||
$data = array( __( 'Date', 'sportspress' ) => $date, __( 'Time', 'sportspress' ) => $time );
|
||||
|
||||
if ( $leagues )
|
||||
$data[ __( 'League', 'sportspress' ) ] = sportspress_array_value( $leagues, 0, '—' )->name;
|
||||
|
||||
if ( $seasons )
|
||||
$data[ __( 'Season', 'sportspress' ) ] = sportspress_array_value( $seasons, 0, '—' )->name;
|
||||
|
||||
|
||||
$output = '<h3>' . __( 'Details', 'sportspress' ) . '</h3>';
|
||||
|
||||
$output .= '<table class="sp-event-details sp-data-table"><tbody>';
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach( $data as $label => $value ):
|
||||
|
||||
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||
$output .= '<th>' . $label . '</th>';
|
||||
$output .= '<td>' . $value . '</td>';
|
||||
$output .= '</tr>';
|
||||
|
||||
$i++;
|
||||
|
||||
endforeach;
|
||||
|
||||
$output .= '</tbody></table>';
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sportspress_event_results' ) ) {
|
||||
function sportspress_event_results( $id ) {
|
||||
|
||||
$teams = (array)get_post_meta( $id, 'sp_team', false );
|
||||
$staff = (array)get_post_meta( $id, 'sp_staff', false );
|
||||
$stats = (array)get_post_meta( $id, 'sp_players', true );
|
||||
$results = sportspress_array_combine( $teams, (array)get_post_meta( $id, 'sp_results', true ) );
|
||||
$statistic_labels = sportspress_get_var_labels( 'sp_statistic' );
|
||||
$result_labels = sportspress_get_var_labels( 'sp_result' );
|
||||
|
||||
$output = '';
|
||||
|
||||
foreach( $teams as $key => $team_id ):
|
||||
if ( ! $team_id ) continue;
|
||||
|
||||
// Get results for players in the team
|
||||
$players = sportspress_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $key );
|
||||
$data = sportspress_array_combine( $players, sportspress_array_value( $stats, $team_id, array() ) );
|
||||
|
||||
$output .= '<h3>' . get_the_title( $team_id ) . '</h3>';
|
||||
|
||||
$output .= '<table class="sp-event-statistics sp-data-table">' . '<thead>' . '<tr>';
|
||||
|
||||
$output .= '<th class="column-number">' . __( '#', 'sportspress' ) . '</th>';
|
||||
$output .= '<th class="column-number">' . __( 'Player', 'sportspress' ) . '</th>';
|
||||
|
||||
foreach( $statistic_labels as $key => $label ):
|
||||
$output .= '<th class="column-' . $key . '">' . $label . '</th>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr>' . '</thead>' . '<tbody>';
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach( $data as $player_id => $row ):
|
||||
|
||||
if ( ! $player_id )
|
||||
continue;
|
||||
|
||||
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||
|
||||
$number = get_post_meta( $player_id, 'sp_number', true );
|
||||
|
||||
// Player number
|
||||
$output .= '<td class="column-number">' . $number . '</td>';
|
||||
|
||||
// Name as link
|
||||
$permalink = get_post_permalink( $player_id );
|
||||
$name = get_the_title( $player_id );
|
||||
$output .= '<td class="column-name">' . '<a href="' . $permalink . '">' . $name . '</a></td>';
|
||||
|
||||
foreach( $statistic_labels as $key => $label ):
|
||||
if ( $key == 'name' )
|
||||
continue;
|
||||
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
|
||||
$value = $row[ $key ];
|
||||
else:
|
||||
$value = 0;
|
||||
endif;
|
||||
$output .= '<td class="column-' . $key . '">' . $value . '</td>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr>';
|
||||
|
||||
$i++;
|
||||
|
||||
endforeach;
|
||||
|
||||
$output .= '</tbody>';
|
||||
|
||||
if ( array_key_exists( 0, $data ) ):
|
||||
|
||||
$output .= '</tfoot><tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||
|
||||
$number = get_post_meta( $player_id, 'sp_number', true );
|
||||
|
||||
// Player number
|
||||
$output .= '<th class="column-number"> </th>';
|
||||
$output .= '<th class="column-name">' . __( 'Total', 'sportspress' ) . '</th>';
|
||||
|
||||
$row = $data[0];
|
||||
|
||||
foreach( $statistic_labels as $key => $label ):
|
||||
if ( $key == 'name' ):
|
||||
continue;
|
||||
endif;
|
||||
$output .= '<th class="column-' . $key . '">' . sportspress_array_value( $row, $key, '—' ) . '</th>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr></tfoot>';
|
||||
|
||||
endif;
|
||||
|
||||
$output .= '</table>';
|
||||
|
||||
endforeach;
|
||||
|
||||
// Initialize and check
|
||||
$table_rows = '';
|
||||
|
||||
@@ -148,6 +101,149 @@ if ( !function_exists( 'sportspress_event_details' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sportspress_event_players' ) ) {
|
||||
function sportspress_event_players( $id ) {
|
||||
|
||||
$teams = (array)get_post_meta( $id, 'sp_team', false );
|
||||
$staff = (array)get_post_meta( $id, 'sp_staff', false );
|
||||
$stats = (array)get_post_meta( $id, 'sp_players', true );
|
||||
$statistic_labels = sportspress_get_var_labels( 'sp_statistic' );
|
||||
|
||||
$output = '';
|
||||
|
||||
foreach( $teams as $key => $team_id ):
|
||||
if ( ! $team_id ) continue;
|
||||
|
||||
// Get results for players in the team
|
||||
$players = sportspress_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $key );
|
||||
$data = sportspress_array_combine( $players, sportspress_array_value( $stats, $team_id, array() ) );
|
||||
|
||||
$output .= '<h3>' . get_the_title( $team_id ) . '</h3>';
|
||||
|
||||
$output .= '<table class="sp-event-statistics sp-data-table">' . '<thead>' . '<tr>';
|
||||
|
||||
$output .= '<th class="column-number">#</th>';
|
||||
$output .= '<th class="column-number">' . __( 'Player', 'sportspress' ) . '</th>';
|
||||
|
||||
foreach( $statistic_labels as $key => $label ):
|
||||
$output .= '<th class="column-' . $key . '">' . $label . '</th>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr>' . '</thead>' . '<tbody>';
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach( $data as $player_id => $row ):
|
||||
|
||||
if ( ! $player_id )
|
||||
continue;
|
||||
|
||||
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||
|
||||
$number = get_post_meta( $player_id, 'sp_number', true );
|
||||
|
||||
// Player number
|
||||
$output .= '<td class="column-number">' . $number . '</td>';
|
||||
|
||||
// Name as link
|
||||
$permalink = get_post_permalink( $player_id );
|
||||
$name = get_the_title( $player_id );
|
||||
$output .= '<td class="column-name">' . '<a href="' . $permalink . '">' . $name . '</a></td>';
|
||||
|
||||
foreach( $statistic_labels as $key => $label ):
|
||||
if ( $key == 'name' )
|
||||
continue;
|
||||
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
|
||||
$value = $row[ $key ];
|
||||
else:
|
||||
$value = 0;
|
||||
endif;
|
||||
$output .= '<td class="column-' . $key . '">' . $value . '</td>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr>';
|
||||
|
||||
$i++;
|
||||
|
||||
endforeach;
|
||||
|
||||
$output .= '</tbody>';
|
||||
|
||||
if ( array_key_exists( 0, $data ) ):
|
||||
|
||||
$output .= '<tfoot><tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||
|
||||
$number = get_post_meta( $player_id, 'sp_number', true );
|
||||
|
||||
// Player number
|
||||
$output .= '<td class="column-number"> </td>';
|
||||
$output .= '<td class="column-name">' . __( 'Total', 'sportspress' ) . '</td>';
|
||||
|
||||
$row = $data[0];
|
||||
|
||||
foreach( $statistic_labels as $key => $label ):
|
||||
if ( $key == 'name' ):
|
||||
continue;
|
||||
endif;
|
||||
$output .= '<td class="column-' . $key . '">' . sportspress_array_value( $row, $key, '—' ) . '</td>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr></tfoot>';
|
||||
|
||||
endif;
|
||||
|
||||
$output .= '</table>';
|
||||
|
||||
endforeach;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( !function_exists( 'sportspress_event_staff' ) ) {
|
||||
function sportspress_event_staff( $id ) {
|
||||
|
||||
$staff = (array)get_post_meta( $id, 'sp_staff', false );
|
||||
|
||||
$output = '';
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( !function_exists( 'sportspress_event_venue' ) ) {
|
||||
function sportspress_event_venue( $id ) {
|
||||
|
||||
$venues = get_the_terms( $id, 'sp_venue' );
|
||||
|
||||
$output = '';
|
||||
|
||||
if ( ! $venues )
|
||||
return $output;
|
||||
|
||||
foreach( $venues as $venue ):
|
||||
|
||||
$t_id = $venue->term_id;
|
||||
$term_meta = get_option( "taxonomy_$t_id" );
|
||||
|
||||
$address = sportspress_array_value( $term_meta, 'sp_address', '' );
|
||||
$latitude = sportspress_array_value( $term_meta, 'sp_latitude', 0 );
|
||||
$longitude = sportspress_array_value( $term_meta, 'sp_longitude', 0 );
|
||||
|
||||
$output .= '<h3>' . $venue->name . '</h3>';
|
||||
$output .= '<div class="sp-google-map" data-address="' . $address . '" data-latitude="' . $latitude . '" data-longitude="' . $longitude . '"></div>';
|
||||
|
||||
endforeach;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sportspress_league_table' ) ) {
|
||||
function sportspress_league_table( $id ) {
|
||||
|
||||
@@ -161,7 +257,7 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
|
||||
// Remove the first row to leave us with the actual data
|
||||
unset( $data[0] );
|
||||
|
||||
$output .= '<th class="column-number">' . __( '#', 'sportspress' ) . '</th>';
|
||||
$output .= '<th class="column-number">#</th>';
|
||||
foreach( $labels as $key => $label ):
|
||||
$output .= '<th class="column-' . $key . '">' . $label . '</th>';
|
||||
endforeach;
|
||||
@@ -274,7 +370,7 @@ if ( !function_exists( 'sportspress_player_list' ) ) {
|
||||
// Remove the first row to leave us with the actual data
|
||||
unset( $data[0] );
|
||||
|
||||
$output .= '<th class="column-number">' . __( '#', 'sportspress' ) . '</th>';
|
||||
$output .= '<th class="column-number">#</th>';
|
||||
foreach( $labels as $key => $label ):
|
||||
$output .= '<th class="column-' . $key . '">' . $label . '</th>';
|
||||
endforeach;
|
||||
|
||||
Reference in New Issue
Block a user