Add Event Specs to Event-Blocks template (+some minor fixes)

This commit is contained in:
savvasha
2019-03-03 16:03:44 +02:00
parent a65b29015c
commit 982a4bec3b
3 changed files with 34 additions and 3 deletions

View File

@@ -448,6 +448,10 @@
clear: both;
}
span.sp_event_spec_label {
font-weight: bold;
}
/* Event Logos Block */
.sp-template-event-logos-block .team-logo {
float: none;

View File

@@ -34,6 +34,7 @@ class SportsPress_Event_Specs {
add_action( 'sportspress_include_post_type_handlers', array( $this, 'include_post_type_handler' ) );
add_action( 'sportspress_event_list_head_row', array( $this, 'event_list_head_row' ), 11 );
add_action( 'sportspress_event_list_row', array( $this, 'event_list_row' ), 11, 2 );
add_action( 'sportspress_event_blocks_after', array( $this, 'event_blocks_after' ), 11, 2 );
// Filters
add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) );
@@ -230,7 +231,7 @@ class SportsPress_Event_Specs {
* Event list head row.
*/
public function event_list_head_row( $usecolumns = array() ) {
if ( is_array( $usecolumns ) && in_array( 'event_specs', $usecolumns ) ) {
if ( sp_column_active( $usecolumns, 'event_specs' ) ) {
$spec_labels = (array)sp_get_var_labels( 'sp_spec', null, false );
if ( empty( $spec_labels ) ) return;
@@ -249,7 +250,7 @@ class SportsPress_Event_Specs {
* Event list row.
*/
public function event_list_row( $event, $usecolumns = array() ) {
if ( is_array( $usecolumns ) && in_array( 'event_specs', $usecolumns ) ) {
if ( sp_column_active( $usecolumns, 'event_specs' ) ) {
$event = new SP_Event( $event );
$specs = $event->specs( false );
$spec_labels = (array)sp_get_var_labels( 'sp_spec', null, false );
@@ -267,6 +268,20 @@ class SportsPress_Event_Specs {
}
}
}
/**
* Add Event Specs after default template of Event blocks is loaded.
*/
public function event_blocks_after( $event, $usecolumns = array() ) {
if ( sp_column_active( $usecolumns, 'event_specs' ) ) {
$event = new SP_Event( $event );
$specs = $event->specs( false );
$spec_labels = (array)sp_get_var_labels( 'sp_spec', null, false );
foreach ( $specs as $spec_label => $spec_value ) {
echo '<div class="sp_event_spec"><span class="sp_event_spec_label">'.$spec_label.':</span><span class="sp_event_spec_value"> '.$spec_value.'</span></div>';
}
}
}
}
endif;

View File

@@ -37,6 +37,7 @@ $defaults = array(
'rows' => get_option( 'sportspress_event_blocks_rows', 5 ),
'orderby' => 'default',
'order' => 'default',
'columns' => null,
'show_all_events_link' => false,
'show_title' => get_option( 'sportspress_event_blocks_show_title', 'no' ) == 'yes' ? true : false,
'show_league' => get_option( 'sportspress_event_blocks_show_league', 'no' ) == 'yes' ? true : false,
@@ -49,9 +50,10 @@ $defaults = array(
extract( $defaults, EXTR_SKIP );
$calendar = new SP_Calendar( $id );
if ( $status != 'default' )
$calendar->status = $status;
if ( $format != 'all' )
if ( $format != 'default' )
$calendar->event_format = $format;
if ( $date != 'default' )
$calendar->date = $date;
@@ -88,6 +90,14 @@ if ( $orderby != 'default' )
if ( $day != 'default' )
$calendar->day = $day;
$data = $calendar->data();
$usecolumns = $calendar->columns;
if ( isset( $columns ) ):
if ( is_array( $columns ) )
$usecolumns = $columns;
else
$usecolumns = explode( ',', $columns );
endif;
if ( $hide_if_empty && empty( $data ) ) return false;
@@ -161,6 +171,7 @@ if ( $title )
?>
<tr class="sp-row sp-post<?php echo ( $i % 2 == 0 ? ' alternate' : '' ); ?>" itemscope itemtype="http://schema.org/SportsEvent">
<td>
<?php do_action( 'sportspress_event_blocks_before', $event, $usecolumns ); ?>
<?php echo implode( $logos, ' ' ); ?>
<time class="sp-event-date" datetime="<?php echo $event->post_date; ?>" itemprop="startDate" content="<?php echo mysql2date( 'Y-m-d\TH:iP', $event->post_date ); ?>">
<?php echo sp_add_link( get_the_time( get_option( 'date_format' ), $event ), $permalink, $link_events ); ?>
@@ -183,6 +194,7 @@ if ( $title )
<h4 class="sp-event-title" itemprop="name">
<?php echo sp_add_link( $event->post_title, $permalink, $link_events ); ?>
</h4>
<?php do_action( 'sportspress_event_blocks_after', $event, $usecolumns ); ?>
</td>
</tr>