Last active
June 21, 2018 17:27
-
-
Save xymox12/7553998 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Readme | |
Thanks to the author of this great plugin: Stephen Harris | |
* (Events Organiser)[http://wordpress.org/plugins/event-organiser/] | |
* (Original Shortcode docs)[http://wp-event-organiser.com/documentation/shortcodes/event-list-shortcode/] | |
This simply extends the Wordpress Events Organiser plugin's shortcode to allow | |
the use of an alternative template (in this case shortcode-group-by-date-event-list.php) | |
and the use of a new attribute, group_by_period. Pagination is also included | |
(add and activate the plugin wp-pagenavi to increase the functionality). | |
Don't use the templating ability of the orginal with this as it won't work as | |
expected - instead modify the child template. | |
## Install | |
* Add the code in extend_eo_events_shortcode.php into your child themes function.php | |
* shortcode-group-by-date-event-list.php goes in your child theme folder | |
## Useage | |
* All attributes of the original [eo_events] shortcode should still | |
work (not fully tested) | |
### New Attribute | |
* group_by_period | |
1. day [default] | |
2. month | |
3. year | |
[eo_group_events_by_date event_start_after=now group_by_period=day numberposts=20] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class EO_Shortcode_Grouped_Lists extends EventOrganiser_Shortcodes { | |
static function init() { | |
add_shortcode('eo_group_events_by_date', array(__CLASS__, 'handle_eventlist_shortcode')); | |
} | |
// Modified copy of orginal handle_eventlist_shortcode | |
static function handle_eventlist_shortcode($atts = array(), $content = null) { | |
$taxs = array('category', 'tag', 'venue'); | |
foreach ($taxs as $tax) { | |
if (isset($atts['event_' . $tax])) { | |
$atts['event-' . $tax] = $atts['event_' . $tax]; | |
unset($atts['event_' . $tax]); | |
} | |
} | |
if ((isset($atts['venue']) && $atts['venue'] == '%this%') || ( isset($atts['event-venue']) && $atts['event-venue'] == '%this%' )) { | |
if (eo_get_venue_slug()) { | |
$atts['event-venue'] = eo_get_venue_slug(); | |
} else { | |
unset($atts['venue']); | |
unset($atts['event-venue']); | |
} | |
} | |
if (isset($atts['users_events']) && strtolower($atts['users_events']) == 'true') { | |
$atts['bookee_id'] = get_current_user_id(); | |
} | |
$args = array( | |
'class' => 'eo-events eo-events-shortcode', | |
'template' => $content, | |
'no_events' => isset($atts['no_events']) ? $atts['no_events'] : '', | |
'type' => 'shortcode-group-by-date', | |
'group_by_period' => isset($atts['group_by_period']) ? $atts['group_by_period'] : '', | |
); | |
// Allow pagination | |
$atts['paged'] = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
return eventorganiser_list_events($atts, $args, 0); | |
} | |
} | |
function extend_events_organiser_class() { | |
EO_Shortcode_Grouped_Lists::init(); | |
} | |
add_action('init', 'extend_events_organiser_class'); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Event List Widget: Standard List | |
* | |
* The template is used for displaying the [eo_group_events_by_date] shortcode | |
*/ | |
global $eo_event_loop,$eo_event_loop_args; | |
//Date % Time format for events | |
$date_format = get_option('date_format'); | |
$time_format = get_option('time_format'); | |
//The list ID / classes | |
$id = ( $eo_event_loop_args['id'] ? 'id="'.$eo_event_loop_args['id'].'"' : '' ); | |
$classes = $eo_event_loop_args['class']; | |
/* Group by day, month, year */ | |
if (isset($eo_event_loop_args['group_by_period'])) { | |
$groupby = $eo_event_loop_args['group_by_period']; | |
} | |
if ($groupby == 'year') { | |
$groupby_str = 'Y'; | |
$time_str = 'jS M G.i'; | |
} elseif ($groupby == 'month') { | |
$groupby_str = 'M Y'; | |
$time_str = 'jS M G.i'; | |
} else { | |
$groupby_str = 'jS M Y'; | |
$time_str = 'G.i'; | |
} | |
$day_check = ''; | |
?> | |
<?php if( $eo_event_loop->have_posts() ): ?> | |
<ul <?php echo $id; ?> class="<?php echo esc_attr($classes);?>" > | |
<?php while( $eo_event_loop->have_posts() ): $eo_event_loop->the_post(); ?> | |
<?php | |
//Generate HTML classes for this event | |
$eo_event_classes = eo_get_event_classes(); | |
//For non-all-day events, include time format | |
$format = ( eo_is_all_day() ? $date_format : $date_format.' '.$time_format ); | |
?> | |
<?php | |
$day = eo_get_the_start($groupby_str); | |
if ($day != $day_check) { | |
if ($day_check != '') { | |
echo '</ul>'; // close the list here | |
} | |
echo '<h2>' . eo_get_the_start($groupby_str) . '</h2>' . "\r\n", '<ul>'; | |
} | |
?> | |
<li class="<?php echo esc_attr(implode(' ',$eo_event_classes)); ?>" > | |
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" ><?php the_title(); ?></a> <?php echo __('on','eventorganiser') . ' '.eo_get_the_start($time_str); ?> at <?php echo eo_get_venue_name(); ?></li> | |
<?php $day_check = $day; ?> | |
<?php endwhile; ?> | |
</ul> | |
<?php | |
if (function_exists('wp_pagenavi')) { | |
wp_pagenavi(array('query' => $eo_event_loop)); | |
} else { ?> | |
<div id="pagination"> | |
<?php get_previous_posts_link('Newer events »', $eo_event_loop->max_num_pages); | |
$get_next_posts_link('« Older events', $eo_event_loop->max_num_pages); ?> | |
</div> <?php | |
} | |
?> | |
<?php elseif( ! empty($eo_event_loop_args['no_events']) ): ?> | |
<ul id="<?php echo esc_attr($id);?>" class="<?php echo esc_attr($classes);?>" > | |
<li class="eo-no-events" > <?php echo $eo_event_loop_args['no_events']; ?> </li> | |
</ul> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment