Created
February 5, 2015 21:09
-
-
Save bappi-d-great/1ef53879d375cbc4836c to your computer and use it in GitHub Desktop.
WPMU Events+ category filter add on calendar view
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 | |
/* | |
Plugin Name: Event Calendar Category Filter | |
Description: Filter by category in the calendar | |
Plugin URI: http://premium.wpmudev.org/project/events-and-booking | |
Version: 0.25 | |
Author: WPMU DEV | |
AddonType: Events | |
*/ | |
/* | |
Detail: This add on will add a category filter in the event calendar archive | |
*/ | |
class Eab_Events_EventCategoryFilter { | |
private $_data; | |
/** | |
* Constructor | |
*/ | |
private function __construct () { | |
$this->_data = Eab_Options::get_instance(); | |
add_action( 'wp_footer', array( $this, 'eab_cat_filter' ) ); | |
} | |
/** | |
* Run the Addon | |
* | |
*/ | |
public static function serve () { | |
$me = new Eab_Events_EventCategoryFilter; | |
} | |
public function eab_cat_filter() { | |
$terms = get_terms( 'eab_events_category' ); | |
$html = '<div class="eab_cat_list"><ul>'; | |
$html .= '<li><a id="cat_all" href="#">Show all</a></li>'; | |
foreach( $terms as $term ){ | |
$html .= '<li><a id="cat_'. $term->slug .'" href="#">' . $term->name . '</a></li>'; | |
} | |
$html .= '</div></ul>'; | |
?> | |
<script type="text/javascript"> | |
jQuery(function($) { | |
if($('.eab-monthly_calendar.eab-shortcode_calendar').length) { | |
$('.eab-monthly_calendar.eab-shortcode_calendar').before( '<?php echo $html ?>' ); | |
$('.eab_cat_list li a').click(function(e){ | |
e.preventDefault(); | |
var id = $(this).attr( 'id' ).split('cat_')[1]; | |
if( id != 'all' ){ | |
$('a.wpmudevevents-calendar-event').fadeIn(); | |
$('a.wpmudevevents-calendar-event').not('.' + id).fadeOut(); | |
}else{ | |
$('a.wpmudevevents-calendar-event').fadeIn(); | |
} | |
return false; | |
}); | |
} | |
}); | |
</script> | |
<style> | |
.eab_cat_list{margin-bottom: 25px; overflow: hidden} | |
.eab_cat_list ul{list-style-type: none !important; margin: 0;} | |
.eab_cat_list ul li{float: left; margin-right: 20px;} | |
</style> | |
<?php | |
} | |
} | |
Eab_Events_EventCategoryFilter::serve(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment