Event list title format selector close #46
This commit is contained in:
@@ -135,6 +135,12 @@ jQuery(document).ready(function($){
|
||||
$(".sp-dummy."+name+"-dummy").val(val).trigger("change");
|
||||
});
|
||||
|
||||
// Title format switcher
|
||||
$(".sp-title-format-select").change(function() {
|
||||
val = $(this).val();
|
||||
$(".sp-title-format").hide().filter(".sp-title-format-"+val).show();
|
||||
});
|
||||
|
||||
// Custom value editor
|
||||
$(".sp-data-table .sp-default-value").click(function() {
|
||||
$(this).hide().siblings(".sp-custom-value").show().find(".sp-custom-value-input").focus();
|
||||
|
||||
@@ -22,20 +22,22 @@ class SP_Meta_Box_Calendar_Data {
|
||||
$calendar = new SP_Calendar( $post );
|
||||
$data = $calendar->data();
|
||||
$usecolumns = $calendar->columns;
|
||||
self::table( $data, $usecolumns );
|
||||
$title_format = $calendar->title_format;
|
||||
self::table( $data, $usecolumns, $title_format );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_title_format', sp_array_value( $_POST, 'sp_title_format', 'title' ) );
|
||||
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin edit table
|
||||
*/
|
||||
public static function table( $data = array(), $usecolumns = null ) {
|
||||
public static function table( $data = array(), $usecolumns = null, $title_format = null ) {
|
||||
if ( is_array( $usecolumns ) )
|
||||
$usecolumns = array_filter( $usecolumns );
|
||||
?>
|
||||
@@ -49,13 +51,11 @@ class SP_Meta_Box_Calendar_Data {
|
||||
<th class="column-event">
|
||||
<label for="sp_columns_event">
|
||||
<input type="checkbox" name="sp_columns[]" value="event" id="sp_columns_event" <?php checked( ! is_array( $usecolumns ) || in_array( 'event', $usecolumns ) ); ?>>
|
||||
<?php _e( 'Event', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<th class="column-teams">
|
||||
<label for="sp_columns_teams">
|
||||
<input type="checkbox" name="sp_columns[]" value="teams" id="sp_columns_teams" <?php checked( ! is_array( $usecolumns ) || in_array( 'teams', $usecolumns ) ); ?>>
|
||||
<?php _e( 'Teams', 'sportspress' ); ?>
|
||||
<select name="sp_title_format" class="sp-title-format-select">
|
||||
<option value="title" <?php selected( $title_format, 'title' ); ?>><?php _e( 'Title', 'sportspress' ); ?></option>
|
||||
<option value="teams" <?php selected( $title_format, 'teams' ); ?>><?php _e( 'Teams', 'sportspress' ); ?></option>
|
||||
<option value="homeaway" <?php selected( $title_format, 'homeaway' ); ?>><?php _e( 'Home', 'sportspress' ); ?> | <?php _e( 'Away', 'sportspress' ); ?></option>
|
||||
</select>
|
||||
</label>
|
||||
</th>
|
||||
<th class="column-time">
|
||||
@@ -92,8 +92,9 @@ class SP_Meta_Box_Calendar_Data {
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td><?php echo get_post_time( get_option( 'date_format' ), false, $event, true ); ?></td>
|
||||
<td><?php echo $event->post_title; ?></td>
|
||||
<td>
|
||||
<div class="sp-title-format sp-title-format-title<?php if ( $title_format != 'title' ): ?> hidden<?php endif; ?>"><?php echo $event->post_title; ?></div>
|
||||
<div class="sp-title-format sp-title-format-teams sp-title-format-homeaway<?php if ( ! in_array( $title_format, array( 'teams', 'homeaway' ) ) ): ?> hidden<?php endif; ?>">
|
||||
<?php
|
||||
if ( $teams ): foreach ( $teams as $team ):
|
||||
$name = get_the_title( $team );
|
||||
@@ -124,6 +125,7 @@ class SP_Meta_Box_Calendar_Data {
|
||||
echo '—';
|
||||
endif;
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
|
||||
@@ -21,12 +21,12 @@ $seasons = get_the_terms( $id, 'sp_season' );
|
||||
$data = array( __( 'Date', 'sportspress' ) => $date, __( 'Time', 'sportspress' ) => $time );
|
||||
|
||||
if ( $leagues ):
|
||||
$league = array_pop( $leagues );
|
||||
$league = array_shift( $leagues );
|
||||
$data[ __( 'League', 'sportspress' ) ] = $league->name;
|
||||
endif;
|
||||
|
||||
if ( $seasons ):
|
||||
$season = array_pop( $seasons );
|
||||
$season = array_shift( $seasons );
|
||||
$data[ __( 'Season', 'sportspress' ) ] = $season->name;
|
||||
endif;
|
||||
?>
|
||||
|
||||
@@ -39,6 +39,7 @@ if ( $order != 'default' )
|
||||
$calendar->order = $order;
|
||||
$data = $calendar->data();
|
||||
$usecolumns = $calendar->columns;
|
||||
$title_format = $calendar->title_format;
|
||||
|
||||
if ( isset( $columns ) ):
|
||||
if ( is_array( $columns ) )
|
||||
@@ -55,11 +56,16 @@ endif;
|
||||
<?php
|
||||
echo '<th class="data-date">' . __( 'Date', 'sportspress' ) . '</th>';
|
||||
|
||||
if ( $usecolumns == null || in_array( 'event', $usecolumns ) )
|
||||
echo '<th class="data-event">' . __( 'Event', 'sportspress' ) . '</th>';
|
||||
|
||||
if ( $usecolumns == null || in_array( 'teams', $usecolumns ) )
|
||||
if ( $usecolumns == null || in_array( 'event', $usecolumns ) ):
|
||||
if ( $title_format == 'homeaway' ):
|
||||
echo '<th class="data-home">' . __( 'Home', 'sportspress' ) . '</th>';
|
||||
echo '<th class="data-away">' . __( 'Away', 'sportspress' ) . '</th>';
|
||||
elseif ( $title_format == 'teams' ):
|
||||
echo '<th class="data-teams">' . __( 'Teams', 'sportspress' ) . '</th>';
|
||||
else:
|
||||
echo '<th class="data-event">' . __( 'Event', 'sportspress' ) . '</th>';
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( $usecolumns == null || in_array( 'time', $usecolumns ) )
|
||||
echo '<th class="data-time">' . __( 'Time/Results', 'sportspress' ) . '</th>';
|
||||
@@ -88,6 +94,7 @@ endif;
|
||||
|
||||
$main_results = array();
|
||||
$teams_output = '';
|
||||
$teams_array = '';
|
||||
|
||||
if ( $teams ):
|
||||
foreach ( $teams as $team ):
|
||||
@@ -107,17 +114,19 @@ endif;
|
||||
endif;
|
||||
|
||||
if ( $link_teams ):
|
||||
$teams_output .= '<a href="' . get_post_permalink( $team ) . '">' . $name . '</a>';
|
||||
$team_output = '<a href="' . get_post_permalink( $team ) . '">' . $name . '</a>';
|
||||
else:
|
||||
$teams_output .= $name;
|
||||
$team_output = $name;
|
||||
endif;
|
||||
|
||||
if ( $team_result != null ):
|
||||
$main_results[] = $team_result;
|
||||
$teams_output .= ' (' . $team_result . ')';
|
||||
$team_output .= ' (' . $team_result . ')';
|
||||
endif;
|
||||
|
||||
$teams_output .= '<br>';
|
||||
$teams_array[] = $team_output;
|
||||
|
||||
$teams_output .= $team_output . '<br>';
|
||||
endif;
|
||||
endforeach;
|
||||
else:
|
||||
@@ -128,23 +137,29 @@ endif;
|
||||
|
||||
echo '<td class="data-date"><a href="' . get_permalink( $event->ID ) . '">' . get_post_time( get_option( 'date_format' ), false, $event, true ) . '</a></td>';
|
||||
|
||||
if ( $usecolumns == null || in_array( 'event', $usecolumns ) )
|
||||
echo '<td class="data-event">' . $event->post_title . '</td>';
|
||||
|
||||
if ( $usecolumns == null || in_array( 'teams', $usecolumns ) ):
|
||||
echo '<td class="data-teams">';
|
||||
echo $teams_output;
|
||||
echo '</td>';
|
||||
if ( $usecolumns == null || in_array( 'event', $usecolumns ) ):
|
||||
if ( $title_format == 'homeaway' ):
|
||||
$team = array_shift( $teams_array );
|
||||
echo '<td class="data-home">' . $team . '</td>';
|
||||
$team = array_shift( $teams_array );
|
||||
echo '<td class="data-away">' . $team . '</td>';
|
||||
else:
|
||||
if ( $title_format == 'teams' ):
|
||||
echo '<td class="data-event">' . $teams_output . '</td>';
|
||||
else:
|
||||
echo '<td class="data-event"><a href="' . get_permalink( $event->ID ) . '">' . $event->post_title . '</a></td>';
|
||||
endif;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( $usecolumns == null || in_array( 'time', $usecolumns ) ):
|
||||
echo '<td class="data-time">';
|
||||
echo '<td class="data-time"><a href="' . get_permalink( $event->ID ) . '">';
|
||||
if ( ! empty( $main_results ) ):
|
||||
echo implode( ' - ', $main_results );
|
||||
else:
|
||||
echo get_post_time( get_option( 'time_format' ), false, $event, true );
|
||||
endif;
|
||||
echo '</td>';
|
||||
echo '</a></td>';
|
||||
endif;
|
||||
|
||||
if ( $usecolumns == null || in_array( 'venue', $usecolumns ) ):
|
||||
|
||||
Reference in New Issue
Block a user