Add blocks layout to calendar close #22
This commit is contained in:
@@ -24,6 +24,7 @@ class SP_Meta_Box_Calendar_Details {
|
||||
$season_id = sp_get_the_term_id( $post->ID, 'sp_season', 0 );
|
||||
$venue_id = sp_get_the_term_id( $post->ID, 'sp_venue', 0 );
|
||||
$team_id = get_post_meta( $post->ID, 'sp_team', true );
|
||||
$order = get_post_meta( $post->ID, 'sp_order', true );
|
||||
?>
|
||||
<div>
|
||||
<p><strong><?php _e( 'Status', 'sportspress' ); ?></strong></p>
|
||||
@@ -97,6 +98,13 @@ class SP_Meta_Box_Calendar_Details {
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Sort Order', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<select name="sp_order">
|
||||
<option value="ASC" <?php selected( 'ASC', $order ); ?>><?php _e( 'Ascending', 'sportspress' ); ?></option>
|
||||
<option value="DESC" <?php selected( 'DESC', $order ); ?>><?php _e( 'Descending', 'sportspress' ); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
@@ -110,5 +118,6 @@ class SP_Meta_Box_Calendar_Details {
|
||||
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_venue', 0 ), 'sp_venue' );
|
||||
update_post_meta( $post_id, 'sp_status', sp_array_value( $_POST, 'sp_status', 0 ) );
|
||||
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', 0 ) );
|
||||
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) );
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,8 @@ class SP_Meta_Box_List_Data {
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
list( $columns, $usecolumns, $data, $placeholders, $merged ) = sp_get_player_list_data( $post->ID, true );
|
||||
$list = new SP_Player_List( $post );
|
||||
list( $columns, $usecolumns, $data, $placeholders, $merged ) = $list->data( true );
|
||||
$adjustments = get_post_meta( $post->ID, 'sp_adjustments', true );
|
||||
self::table( $columns, $usecolumns, $data, $placeholders, $adjustments );
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class SP_Meta_Box_List_Details {
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Sort by:', 'sportspress' ); ?></strong></p>
|
||||
<p><strong><?php _e( 'Sort by', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<?php
|
||||
$args = array(
|
||||
@@ -87,7 +87,7 @@ class SP_Meta_Box_List_Details {
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Sort Order:', 'sportspress' ); ?></strong></p>
|
||||
<p><strong><?php _e( 'Sort Order', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<select name="sp_order">
|
||||
<option value="ASC" <?php selected( 'ASC', $order ); ?>><?php _e( 'Ascending', 'sportspress' ); ?></option>
|
||||
|
||||
@@ -15,6 +15,9 @@ class SP_Calendar extends SP_Custom_Post {
|
||||
/** @var array The events status. */
|
||||
public $status;
|
||||
|
||||
/** @var array The events order. */
|
||||
public $order;
|
||||
|
||||
/**
|
||||
* __construct function.
|
||||
*
|
||||
@@ -31,9 +34,13 @@ class SP_Calendar extends SP_Custom_Post {
|
||||
endif;
|
||||
|
||||
$this->status = $this->__get( 'status' );
|
||||
$this->order = $this->__get( 'order' );
|
||||
|
||||
if ( ! $this->status )
|
||||
$this->status = 'any';
|
||||
|
||||
if ( ! $this->order )
|
||||
$this->order = 'ASC';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,8 +56,8 @@ class SP_Calendar extends SP_Custom_Post {
|
||||
'post_type' => 'sp_event',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'post_date',
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'date',
|
||||
'order' => $this->order,
|
||||
'post_status' => $this->status,
|
||||
'tax_query' => array(
|
||||
'relation' => 'AND'
|
||||
|
||||
@@ -30,6 +30,7 @@ class SP_Formats {
|
||||
'calendar' => array(
|
||||
'calendar' => __( 'Calendar', 'sportspress' ),
|
||||
'list' => __( 'List', 'sportspress' ),
|
||||
'blocks' => __( 'Blocks', 'sportspress' ),
|
||||
),
|
||||
'list' => array(
|
||||
'list' => __( 'List', 'sportspress' ),
|
||||
|
||||
@@ -151,14 +151,10 @@ if ( ! function_exists( 'sportspress_output_calendar' ) ) {
|
||||
function sportspress_output_calendar() {
|
||||
$id = get_the_ID();
|
||||
$format = get_post_meta( $id, 'sp_format', true );
|
||||
switch ( $format ):
|
||||
case 'list':
|
||||
sp_get_template( 'event-list.php', array( 'id' => $id ) );
|
||||
break;
|
||||
default:
|
||||
sp_get_template( 'event-calendar.php', array( 'id' => $id ) );
|
||||
break;
|
||||
endswitch;
|
||||
if ( array_key_exists( $format, SP()->formats->calendar ) )
|
||||
sp_get_template( 'event-' . $format . '.php', array( 'id' => $id ) );
|
||||
else
|
||||
sp_get_template( 'event-calendar.php', array( 'id' => $id ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,14 +233,10 @@ if ( ! function_exists( 'sportspress_output_player_list' ) ) {
|
||||
function sportspress_output_player_list() {
|
||||
$id = get_the_ID();
|
||||
$format = get_post_meta( $id, 'sp_format', true );
|
||||
switch ( $format ):
|
||||
case 'gallery':
|
||||
sp_get_template( 'player-gallery.php', array( 'id' => $id ) );
|
||||
break;
|
||||
default:
|
||||
sp_get_template( 'player-list.php', array( 'id' => $id ) );
|
||||
break;
|
||||
endswitch;
|
||||
if ( array_key_exists( $format, SP()->formats->list ) )
|
||||
sp_get_template( 'player-' . $format . '.php', array( 'id' => $id ) );
|
||||
else
|
||||
sp_get_template( 'player-list.php', array( 'id' => $id ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,14 +156,6 @@ function sportspress_pre_get_posts( $query ) {
|
||||
if ( is_sp_config_type( $post_type ) ):
|
||||
$query->set( 'orderby', 'menu_order' );
|
||||
$query->set( 'order', 'ASC' );
|
||||
elseif ( $post_type == 'sp_event' ):
|
||||
$query->set( 'orderby', 'post_date' );
|
||||
$query->set( 'order', 'ASC' );
|
||||
endif;
|
||||
else:
|
||||
$post_type = $query->get( 'post_type' );
|
||||
if ( $query->is_post_type_archive && $post_type == 'sp_event' ):
|
||||
$query->set( 'order' , 'ASC' );
|
||||
endif;
|
||||
endif;
|
||||
|
||||
|
||||
94
includes/widgets/class-sp-widget-event-blocks.php
Normal file
94
includes/widgets/class-sp-widget-event-blocks.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
class SP_Widget_Event_Blocks extends WP_Widget {
|
||||
|
||||
function __construct() {
|
||||
$widget_ops = array('classname' => 'widget_sp_event_blocks', 'description' => __( 'A list of events.', 'sportspress' ) );
|
||||
parent::__construct('sp_event_blocks', __( 'SportsPress Event Blocks', 'sportspress' ), $widget_ops);
|
||||
}
|
||||
|
||||
function widget( $args, $instance ) {
|
||||
extract($args);
|
||||
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
|
||||
$id = empty($instance['id']) ? null : $instance['id'];
|
||||
$status = empty($instance['status']) ? 'default' : $instance['status'];
|
||||
$number = empty($instance['number']) ? null : $instance['number'];
|
||||
$order = empty($instance['order']) ? 'default' : $instance['order'];
|
||||
$show_all_events_link = empty($instance['show_all_events_link']) ? false : $instance['show_all_events_link'];
|
||||
echo $before_widget;
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
sp_get_template( 'event-blocks.php', array( 'id' => $id, 'status' => $status, 'number' => $number, 'order' => $order, 'show_all_events_link' => $show_all_events_link ) );
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
function update( $new_instance, $old_instance ) {
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
$instance['id'] = intval($new_instance['id']);
|
||||
$instance['status'] = $new_instance['status'];
|
||||
$instance['number'] = intval($new_instance['number']);
|
||||
$instance['order'] = strip_tags($new_instance['order']);
|
||||
$instance['show_all_events_link'] = $new_instance['show_all_events_link'];
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function form( $instance ) {
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'status' => 'default', 'number' => 5, 'order' => 'default', 'show_all_events_link' => true ) );
|
||||
$title = strip_tags($instance['title']);
|
||||
$id = intval($instance['id']);
|
||||
$status = $instance['status'];
|
||||
$number = intval($instance['number']);
|
||||
$order = strip_tags($instance['order']);
|
||||
$show_all_events_link = $instance['show_all_events_link'];
|
||||
?>
|
||||
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Calendar', 'sportspress' ) ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_calendar',
|
||||
'show_option_all' => __( 'All', 'sportspress' ),
|
||||
'name' => $this->get_field_name('id'),
|
||||
'id' => $this->get_field_id('id'),
|
||||
'selected' => $id,
|
||||
'values' => 'ID',
|
||||
'class' => 'sp-event-calendar-select widefat',
|
||||
);
|
||||
if ( ! sp_dropdown_pages( $args ) ):
|
||||
sp_post_adder( 'sp_calendar', __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('status'); ?>"><?php _e( 'Status:', 'sportspress' ); ?></label>
|
||||
<?php
|
||||
$args = array(
|
||||
'show_option_default' => __( 'Default', 'sportspress' ),
|
||||
'name' => $this->get_field_name('status'),
|
||||
'id' => $this->get_field_id('status'),
|
||||
'selected' => $status,
|
||||
'class' => 'sp-event-status-select widefat',
|
||||
);
|
||||
sp_dropdown_statuses( $args );
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e( 'Number of events to show:', 'sportspress' ); ?></label>
|
||||
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo esc_attr($number); ?>" size="3"></p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('order'); ?>"><?php _e( 'Sort Order:', 'sportspress' ); ?></label>
|
||||
<select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="sp-select-order widefat">
|
||||
<option value="default" <?php selected( 'default', $order ); ?>><?php _e( 'Default', 'sportspress' ); ?></option>
|
||||
<option value="ASC" <?php selected( 'ASC', $order ); ?>><?php _e( 'Ascending', 'sportspress' ); ?></option>
|
||||
<option value="DESC" <?php selected( 'DESC', $order ); ?>><?php _e( 'Descending', 'sportspress' ); ?></option>
|
||||
</select></p>
|
||||
|
||||
<p class="sp-event-calendar-show-all-toggle<?php if ( ! $id ): ?> hidden<?php endif; ?>"><input class="checkbox" type="checkbox" id="<?php echo $this->get_field_id('show_all_events_link'); ?>" name="<?php echo $this->get_field_name('show_all_events_link'); ?>" value="1" <?php checked( $show_all_events_link, 1 ); ?>>
|
||||
<label for="<?php echo $this->get_field_id('show_all_events_link'); ?>"><?php _e( 'Display link to view all events', 'sportspress' ); ?></label></p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
register_widget( 'SP_Widget_Event_Blocks' );
|
||||
@@ -13,11 +13,12 @@ class SP_Widget_Event_List extends WP_Widget {
|
||||
$status = empty($instance['status']) ? 'default' : $instance['status'];
|
||||
$number = empty($instance['number']) ? null : $instance['number'];
|
||||
$columns = empty($instance['columns']) ? null : $instance['columns'];
|
||||
$order = empty($instance['order']) ? 'default' : $instance['order'];
|
||||
$show_all_events_link = empty($instance['show_all_events_link']) ? false : $instance['show_all_events_link'];
|
||||
echo $before_widget;
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
sp_get_template( 'event-list.php', array( 'id' => $id, 'status' => $status, 'number' => $number, 'columns' => $columns, 'show_all_events_link' => $show_all_events_link ) );
|
||||
sp_get_template( 'event-list.php', array( 'id' => $id, 'status' => $status, 'number' => $number, 'columns' => $columns, 'order' => $order, 'show_all_events_link' => $show_all_events_link ) );
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
@@ -28,18 +29,20 @@ class SP_Widget_Event_List extends WP_Widget {
|
||||
$instance['status'] = $new_instance['status'];
|
||||
$instance['number'] = intval($new_instance['number']);
|
||||
$instance['columns'] = (array)$new_instance['columns'];
|
||||
$instance['order'] = strip_tags($new_instance['order']);
|
||||
$instance['show_all_events_link'] = $new_instance['show_all_events_link'];
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
function form( $instance ) {
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'status' => 'default', 'number' => 5, 'columns' => null, 'show_all_events_link' => true ) );
|
||||
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'status' => 'default', 'number' => 5, 'columns' => null, 'order' => 'default', 'show_all_events_link' => true ) );
|
||||
$title = strip_tags($instance['title']);
|
||||
$id = intval($instance['id']);
|
||||
$status = $instance['status'];
|
||||
$number = intval($instance['number']);
|
||||
$columns = $instance['columns'];
|
||||
$order = strip_tags($instance['order']);
|
||||
$show_all_events_link = $instance['show_all_events_link'];
|
||||
?>
|
||||
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
|
||||
@@ -78,6 +81,13 @@ class SP_Widget_Event_List extends WP_Widget {
|
||||
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e( 'Number of events to show:', 'sportspress' ); ?></label>
|
||||
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo esc_attr($number); ?>" size="3"></p>
|
||||
|
||||
<p><label for="<?php echo $this->get_field_id('order'); ?>"><?php _e( 'Sort Order:', 'sportspress' ); ?></label>
|
||||
<select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="sp-select-order widefat">
|
||||
<option value="default" <?php selected( 'default', $order ); ?>><?php _e( 'Default', 'sportspress' ); ?></option>
|
||||
<option value="ASC" <?php selected( 'ASC', $order ); ?>><?php _e( 'Ascending', 'sportspress' ); ?></option>
|
||||
<option value="DESC" <?php selected( 'DESC', $order ); ?>><?php _e( 'Descending', 'sportspress' ); ?></option>
|
||||
</select></p>
|
||||
|
||||
<p class="sp-prefs">
|
||||
<?php _e( 'Columns:', 'sportspress' ); ?><br>
|
||||
<?php
|
||||
|
||||
@@ -19,7 +19,7 @@ class SP_Widget_Player_list extends WP_Widget {
|
||||
if ( $title )
|
||||
echo $before_title . $title . $after_title;
|
||||
echo '<div id="sp_player_list_wrap">';
|
||||
sp_get_template( 'player-list.php', array( 'id' => $id, 'number' => $number, 'performance' => $performance, 'orderby' => $orderby , 'order' => $order, 'show_all_players_link' => $show_all_players_link ) );
|
||||
sp_get_template( 'player-list.php', array( 'id' => $id, 'number' => $number, 'performance' => $performance, 'orderby' => $orderby, 'order' => $order, 'show_all_players_link' => $show_all_players_link ) );
|
||||
echo '</div>';
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user