Add Events widget

This commit is contained in:
Brian Miyaji
2014-02-03 05:51:09 +11:00
parent eca5c08d16
commit 39d7bbac7f
18 changed files with 323 additions and 30 deletions

View File

@@ -80,7 +80,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
<tr>';
if ( $previous ) {
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . add_query_arg( array( 'sp_year' => $previous->year, 'sp_month' => $previous->month ) ) . '" title="' . esc_attr( sprintf(__('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a data-tooltip data-options="disable_for_touch:true" class="has-tooltip tip-right" href="' . add_query_arg( array( 'sp_year' => $previous->year, 'sp_month' => $previous->month ) ) . '" title="' . esc_attr( sprintf(__('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
} else {
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
}
@@ -88,7 +88,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
$calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
if ( $next ) {
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . add_query_arg( array( 'sp_year' => $next->year, 'sp_month' => $next->month ) ) . '" title="' . esc_attr( sprintf(__('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a data-tooltip data-options="disable_for_touch:true" class="has-tooltip tip-left" href="' . add_query_arg( array( 'sp_year' => $next->year, 'sp_month' => $next->month ) ) . '" title="' . esc_attr( sprintf(__('%1$s %2$s', 'calendar caption', 'sportspress'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
} else {
$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
}
@@ -157,7 +157,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
$calendar_output .= '<td>';
if ( array_key_exists($day, $daywithpost) ) // any posts today?
$calendar_output .= '<a href="' . ( sizeof( $daywithpost[ $day ] ) > 1 ? add_query_arg( array( 'post_type' => 'sp_event' ), get_day_link( $thisyear, $thismonth, $day ) ) : get_permalink( $daywithpost[ $day ][0] ) ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
$calendar_output .= '<a data-tooltip data-options="disable_for_touch:true" class="has-tip" href="' . ( sizeof( $daywithpost[ $day ] ) > 1 ? add_query_arg( array( 'post_type' => 'sp_event' ), get_day_link( $thisyear, $thismonth, $day ) ) . '" title="' . sprintf( '%s Events', ( sizeof( $daywithpost[ $day ] ) ) ) : get_permalink( $daywithpost[ $day ][0] ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) ) . "\">$day</a>";
else
$calendar_output .= $day;
$calendar_output .= '</td>';

View File

@@ -0,0 +1,65 @@
<?php
if ( !function_exists( 'sportspress_events' ) ) {
function sportspress_events( $args = array() ) {
$options = array(
'post_type' => 'sp_event',
'posts_per_page' => 1,
'post_status' => 'publish',
'tax_query' => array(),
);
if ( isset( $args['number'] ) ):
$options['posts_per_page'] = $args['number'];
endif;
if ( isset( $args['status'] ) && $args['status'] == 'any' || $args['status'] == 'scheduled' ):
$options['post_status'] = array( 'publish', 'future' );
endif;
if ( isset( $args['league'] ) ):
$options['tax_query'][] = array(
'taxonomy' => 'sp_league',
'field' => 'id',
'terms' => $league
);
endif;
if ( isset( $args['season'] ) ):
$options['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'id',
'terms' => $season
);
endif;
if ( isset( $args['venue'] ) ):
$options['tax_query'][] = array(
'taxonomy' => 'sp_venue',
'field' => 'id',
'terms' => $venue
);
endif;
$query = new WP_Query( $options );
if ( $query->have_posts() ):
$output = '<ul class="sp-events-list">';
while ( $query->have_posts() ):
$query->the_post();
$output .=
'<li>' .
'<span class="post-date">' . get_the_date() . '</span>' .
'<a href="' . get_permalink() . '">' . get_the_title() . '</a>' .
'</li>';
endwhile;
$output .= '</ul>';
wp_reset_postdata();
endif;
return apply_filters( 'sportspress_events', $output );
}
}

View File

@@ -17,19 +17,23 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
$seasons = get_the_terms( $id, 'sp_season' );
$terms = array();
if ( sizeof( $leagues ) ):
if ( $leagues ):
$league = reset( $leagues );
$terms[] = $league->name;
endif;
if ( sizeof( $seasons ) ):
if ( $seasons ):
$season = reset( $seasons );
$terms[] = $season->name;
endif;
$title = sizeof( $terms ) ? implode( ' &mdash; ', $terms ) : get_the_title( $id );
$output = '<h4 class="sp-table-caption">' . $title . '</h4>' .
'<div class="sp-table-wrapper">' .
if ( ! is_singular( 'sp_table' ) )
$output = '<h4 class="sp-table-caption"><a href="' . get_permalink( $id ) . '">' . $title . '</a></h4>';
else
$output = '<h4 class="sp-table-caption">' . $title . '</h4>';
$output .= '<div class="sp-table-wrapper">' .
'<table class="sp-league-table sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
$data = sportspress_get_league_table_data( $id );