Add events list template
This commit is contained in:
@@ -67,7 +67,7 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
|
||||
endif;
|
||||
|
||||
if ( $team_result != null ):
|
||||
echo '<strong>' . $team_result . '</strong> ';
|
||||
echo '<strong class="result">' . $team_result . '</strong> ';
|
||||
endif;
|
||||
|
||||
echo $team->post_title;
|
||||
|
||||
@@ -49,9 +49,15 @@ function sportspress_save_post( $post_id ) {
|
||||
// Update venue taxonomy
|
||||
wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_venue', 0 ), 'sp_venue' );
|
||||
|
||||
// Update video
|
||||
update_post_meta( $post_id, 'sp_video', sportspress_array_value( $_POST, 'sp_video', null ) );
|
||||
|
||||
break;
|
||||
|
||||
case ( 'sp_calendar' ):
|
||||
|
||||
// Update columns array
|
||||
update_post_meta( $post_id, 'sp_columns', sportspress_array_value( $_POST, 'sp_columns', array() ) );
|
||||
|
||||
// Update format
|
||||
update_post_meta( $post_id, 'sp_format', sportspress_array_value( $_POST, 'sp_format', 'calendar' ) );
|
||||
@@ -171,7 +177,7 @@ function sportspress_save_post( $post_id ) {
|
||||
case ( 'sp_list' ):
|
||||
|
||||
// Update statistics array
|
||||
update_post_meta( $post_id, 'sp_statistics', sportspress_array_value( $_POST, 'sp_statistics', array() ) );
|
||||
update_post_meta( $post_id, 'sp_columns', sportspress_array_value( $_POST, 'sp_columns', array() ) );
|
||||
|
||||
// Update players array
|
||||
update_post_meta( $post_id, 'sp_players', sportspress_array_value( $_POST, 'sp_players', array() ) );
|
||||
|
||||
@@ -13,16 +13,42 @@ function sportspress_default_event_content( $content ) {
|
||||
$results = sportspress_event_results();
|
||||
$players = sportspress_event_players();
|
||||
$staff = sportspress_event_staff();
|
||||
$id = get_the_ID();
|
||||
$video_url = get_post_meta( $id, 'sp_video', true );
|
||||
if ( $video_url ):
|
||||
global $wp_embed;
|
||||
$video = $wp_embed->autoembed( $video_url );
|
||||
else:
|
||||
$video = '';
|
||||
endif;
|
||||
if ( $results ):
|
||||
$content = $results . $details . $players . $staff . $content;
|
||||
$content = $video . $results . $details . $players . $staff . $content;
|
||||
else:
|
||||
$venue = sportspress_event_venue();
|
||||
$content = $details . $venue . $players . $staff . $content;
|
||||
$content = $video . $details . $venue . $players . $staff . $content;
|
||||
endif;
|
||||
endif;
|
||||
return $content;
|
||||
}
|
||||
add_filter( 'the_content', 'sportspress_default_event_content' );
|
||||
add_filter( 'the_content', 'sportspress_default_event_content', 7 );
|
||||
|
||||
function sportspress_default_calendar_content( $content ) {
|
||||
if ( is_singular( 'sp_calendar' ) && in_the_loop() ):
|
||||
$id = get_the_ID();
|
||||
$format = get_post_meta( $id, 'sp_format', true );
|
||||
switch ( $format ):
|
||||
case 'list':
|
||||
$calendar = sportspress_events_list( $id );
|
||||
break;
|
||||
default:
|
||||
$calendar = sportspress_events_calendar( $id, true, false );
|
||||
break;
|
||||
endswitch;
|
||||
$content = $calendar . $content;
|
||||
endif;
|
||||
return $content;
|
||||
}
|
||||
add_filter( 'the_content', 'sportspress_default_calendar_content' );
|
||||
|
||||
function sportspress_default_team_content( $content ) {
|
||||
if ( is_singular( 'sp_team' ) && in_the_loop() ):
|
||||
|
||||
@@ -143,9 +143,9 @@ function sportspress_calendar_details_meta( $post, $test ) {
|
||||
|
||||
function sportspress_calendar_events_meta( $post ) {
|
||||
|
||||
$data = sportspress_get_calendar_data( $post->ID );
|
||||
list( $data, $usecolumns ) = sportspress_get_calendar_data( $post->ID, true );
|
||||
|
||||
sportspress_edit_calendar_table( $data );
|
||||
sportspress_edit_calendar_table( $data, $usecolumns );
|
||||
|
||||
sportspress_nonce();
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ function sportspress_event_meta_init( $post ) {
|
||||
add_meta_box( 'sp_formatdiv', __( 'Format', 'sportspress' ), 'sportspress_event_format_meta', 'sp_event', 'side', 'high' );
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_event_details_meta', 'sp_event', 'side', 'high' );
|
||||
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sportspress_event_team_meta', 'sp_event', 'side', 'default' );
|
||||
add_meta_box( 'sp_videodiv', __( 'Video', 'sportspress' ), 'sportspress_event_video_meta', 'sp_event', 'side', 'low' );
|
||||
if ( sizeof( $teams ) > 0 )
|
||||
add_meta_box( 'sp_resultsdiv', __( 'Results', 'sportspress' ), 'sportspress_event_results_meta', 'sp_event', 'normal', 'high' );
|
||||
|
||||
@@ -193,6 +194,26 @@ function sportspress_event_team_meta( $post ) {
|
||||
sportspress_nonce();
|
||||
}
|
||||
|
||||
function sportspress_event_video_meta( $post ) {
|
||||
$video = get_post_meta( $post->ID, 'sp_video', true );
|
||||
if ( $video ):
|
||||
?>
|
||||
<fieldset class="sp-video-embed">
|
||||
<?php echo apply_filters( 'the_content', '[embed width="254"]' . $video . '[/embed]' ); ?>
|
||||
<p><a href="#" class="sp-remove-video"><?php _e( 'Remove video', 'sportspress' ); ?></a></p>
|
||||
</fieldset>
|
||||
<?php endif; ?>
|
||||
<fieldset class="sp-video-field hidden">
|
||||
<p><strong><?php _e( 'URL', 'sportspress' ); ?></strong></p>
|
||||
<p><input class="widefat" type="text" name="sp_video" id="sp_video" value="<?php echo $video; ?>"></p>
|
||||
<p><a href="#" class="sp-remove-video"><?php _e( 'Cancel', 'sportspress' ); ?></a></p>
|
||||
</fieldset>
|
||||
<fieldset class="sp-video-adder<?php if ( $video ): ?> hidden<?php endif; ?>">
|
||||
<p><a href="#" class="sp-add-video"><?php _e( 'Add video', 'sportspress' ); ?></a></p>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
|
||||
function sportspress_event_statistics_meta( $post ) {
|
||||
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||
$stats = (array)get_post_meta( $post->ID, 'sp_players', true );
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
if ( !function_exists( 'sportspress_events_calendar' ) ) {
|
||||
function sportspress_events_calendar( $initial = true ) {
|
||||
function sportspress_events_calendar( $id = null, $single = false, $initial = true ) {
|
||||
|
||||
global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
|
||||
|
||||
@@ -8,6 +8,8 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
|
||||
if ( !$posts )
|
||||
return;
|
||||
|
||||
$caption_tag = ( $single ? 'h4' : 'caption' );
|
||||
|
||||
// week_begins = 0 stands for Sunday
|
||||
$week_begins = intval(get_option('start_of_week'));
|
||||
|
||||
@@ -56,7 +58,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
|
||||
$calendar_caption = _x('%1$s %2$s', 'calendar caption', 'sportspress');
|
||||
$calendar_output = '
|
||||
<table id="wp-calendar">
|
||||
<caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
|
||||
<' . $caption_tag . ' class="sp-table-caption">' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</' . $caption_tag . '>
|
||||
<thead>
|
||||
<tr>';
|
||||
|
||||
|
||||
121
admin/templates/events-list.php
Normal file
121
admin/templates/events-list.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
if ( !function_exists( 'sportspress_events_list' ) ) {
|
||||
function sportspress_events_list( $id = null, $args = '' ) {
|
||||
|
||||
if ( ! $id )
|
||||
$id = get_the_ID();
|
||||
|
||||
$options = get_option( 'sportspress' );
|
||||
$main_result = sportspress_array_value( $options, 'main_result', null );
|
||||
|
||||
$defaults = array(
|
||||
);
|
||||
|
||||
$r = wp_parse_args( $args, $defaults );
|
||||
|
||||
$output = '<div class="sp-table-wrapper">' .
|
||||
'<table class="sp-events-list sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
|
||||
|
||||
list( $data, $usecolumns ) = sportspress_get_calendar_data( $id, true );
|
||||
|
||||
$output .= '<th class="column-date">' . __( 'Date', 'sportspress' ). '</th>';
|
||||
|
||||
if ( in_array( 'event', $usecolumns ) )
|
||||
$output .= '<th class="column-event">' . __( 'Event', 'sportspress' ). '</th>';
|
||||
|
||||
if ( in_array( 'teams', $usecolumns ) )
|
||||
$output .= '<th class="column-teams">' . __( 'Teams', 'sportspress' ). '</th>';
|
||||
|
||||
if ( in_array( 'time', $usecolumns ) )
|
||||
$output .= '<th class="column-time">' . __( 'Time', 'sportspress' ). '</th>';
|
||||
|
||||
if ( in_array( 'article', $usecolumns ) )
|
||||
$output .= '<th class="column-article">' . __( 'Article', 'sportspress' ). '</th>';
|
||||
|
||||
$output .= '</tr>' . '</thead>' . '<tbody>';
|
||||
|
||||
$i = 0;
|
||||
foreach ( $data as $event ):
|
||||
$teams = get_post_meta( $event->ID, 'sp_team' );
|
||||
$results = get_post_meta( $event->ID, 'sp_results', true );
|
||||
$video = get_post_meta( $event->ID, 'sp_video', true );
|
||||
|
||||
$output .= '<tr class="sp-row sp-post' . ( $i % 2 == 0 ? ' alternate' : '' ) . '">';
|
||||
|
||||
$output .= '<td class="column-date">' . get_post_time( get_option( 'date_format' ), false, $event ) . '</td>';
|
||||
|
||||
if ( in_array( 'event', $usecolumns ) )
|
||||
$output .= '<td class="column-event">' . $event->post_title . '</td>';
|
||||
|
||||
if ( in_array( 'teams', $usecolumns ) ):
|
||||
$output .= '<td class="column-teams">';
|
||||
|
||||
$teams = get_post_meta( $event->ID, 'sp_team', false );
|
||||
if ( $teams ):
|
||||
foreach ( $teams as $team ):
|
||||
$name = get_the_title( $team );
|
||||
if ( $name ):
|
||||
$team_results = sportspress_array_value( $results, $team, null );
|
||||
|
||||
if ( $main_result ):
|
||||
$team_result = sportspress_array_value( $team_results, $main_result, null );
|
||||
else:
|
||||
if ( is_array( $team_results ) ):
|
||||
end( $team_results );
|
||||
$team_result = prev( $team_results );
|
||||
else:
|
||||
$team_result = null;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
$output .= $name;
|
||||
|
||||
if ( $team_result != null ):
|
||||
$output .= ' (' . $team_result . ')';
|
||||
endif;
|
||||
|
||||
$output .= '<br>';
|
||||
endif;
|
||||
endforeach;
|
||||
else:
|
||||
$output .= '—';
|
||||
endif;
|
||||
|
||||
$output .= '</td>';
|
||||
endif;
|
||||
|
||||
if ( in_array( 'time', $usecolumns ) )
|
||||
$output .= '<td class="column-time">' . get_post_time( get_option( 'time_format' ), false, $event ) . '</td>';
|
||||
|
||||
if ( in_array( 'article', $usecolumns ) ):
|
||||
$output .= '<td class="column-article">
|
||||
<a href="' . get_permalink( $event->ID ) . '#sp_articlediv">';
|
||||
|
||||
if ( $video ):
|
||||
$output .= '<div class="dashicons dashicons-video-alt"></div>';
|
||||
elseif ( has_post_thumbnail( $event->ID ) ):
|
||||
$output .= '<div class="dashicons dashicons-camera"></div>';
|
||||
endif;
|
||||
if ( $event->post_content !== null ):
|
||||
if ( $event->post_status == 'publish' ):
|
||||
$output .= __( 'Recap', 'sportspress' );
|
||||
else:
|
||||
$output .= __( 'Preview', 'sportspress' );
|
||||
endif;
|
||||
endif;
|
||||
|
||||
$output .= '</a>
|
||||
</td>';
|
||||
endif;
|
||||
|
||||
$output .= '</tr>';
|
||||
|
||||
$i++;
|
||||
endforeach;
|
||||
|
||||
$output .= '</tbody>' . '</table>' . '</div>';
|
||||
|
||||
return apply_filters( 'sportspress_events_list', $output );
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user