Home › Forums › Calendar Products › Events Calendar PRO › Gridview Based On Category
- This topic has 34 replies, 7 voices, and was last updated 8 years, 10 months ago by Support Droid.
-
AuthorPosts
-
February 29, 2012 at 5:46 pm #15960rudeetoursMember
We are looking to input a gridview calendar based on a specific category. Is there a snippet of code that I can input into the gridview.php that will limit the events to the specified category?
February 29, 2012 at 7:00 pm #15990RobMemberHey Matt. This should be doable, but let me get our dev Jonah to respond directly just to be sure. Stay tuned.
March 1, 2012 at 11:41 am #16081JonahParticipantHi Matt,
Are you looking to list out your different categories or do you just want to limit the main calendar to a category or categories?
March 20, 2012 at 1:59 pm #16982DemitriParticipantI’m looking for something similar – I need to restrict elements from showing up on the grid view. I have several seasonal events that span months and I need to hide them from showing up every day.
March 20, 2012 at 3:53 pm #16993JonahParticipantHi Demitri, you can exclude categories from your calendar like so. Paste this into your functions.php file: https://gist.github.com/2142161
Note: Change ‘2012’ to whatever the slug is of the event category you want to exclude. If you want to exclude more than one category see this: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
This should only affect your calendar page and nothing else but you may need to modify the conditionals to get it to work right for you.
March 22, 2012 at 2:21 pm #17081DemitriParticipantHi Jonah – This worked – however rather than exclude, it included the category. (When I first added the code, it excluded everything, and when I added a “gridview” category to my events, it snagged them and put them on the calendar.)
Thanks for the help!
March 22, 2012 at 2:23 pm #17082JonahParticipantHi Demitri, the default operator for tax_query is IN so you need to specify it like so:
‘operator’ => ‘NOT IN’
Look at the tax_query doco for more on that.
March 28, 2012 at 1:05 pm #17278DemitriParticipantHi –
I need to reverse this so that I can exclude a category on the list view. I’ve tried to decipher the conditionals to no avail (all is see is !is_single) but I fail to see how I can access the list view. Any help would be greatly appreciated!March 29, 2012 at 10:46 am #17339JonahParticipantHi Demitri, I need to get some help from one of our other developers on this. Stay tuned!
March 31, 2012 at 3:12 pm #17458Joey KudishMemberHi Demitri,
Throw this into a small plugin or into your functions.php file: https://gist.github.com/2269019 and make sure to replace the “not-in-this-category” on line 19 with the category slug you want to exclude.Cheers
April 10, 2012 at 8:07 am #17770rudeetoursMemberI’ve taken over the project from rudeetours above. I have four categories. Each category is supposed to display a calendar (grid view) on a different page. Each page uses a different template. So, can I add similar code (but to include one category only) to my template? This is what I’ve got for one of the page templates. (currently getting a fatal error here http://rudeetours.com/tours/winter-wildlife/)
Can you guide me on where/how I can use code similar to what is here. https://gist.github.com/2269019
...<a href=''>
←<a href=''>
→<a class='tec-button-off' href=''>pluginDomain)?>
<a class='tec-button-on' href=''>pluginDomain)?>get_event_taxonomy() ) ) {
$cat = get_term_by( 'slug', get_query_var('term'), $sp_ecp->get_event_taxonomy() );
$eventCat = (int) $cat->term_id;
$eventPosts = sp_get_events( array( 'eventCat' => $eventCat, 'time_order' => 'ASC' ) );
} // not in a cat
else {
$eventCat = 'Winter Wildlife';
$eventPosts = sp_get_events(array( 'eventCat' => $eventCat, 'time_order' => 'ASC' ));
}$eventCat = 'Dolphin Watching';
$daysInMonth = isset($date) ? date("t", $date) : date("t");
$startOfWeek = get_option( 'start_of_week', 0 );
list( $year, $month ) = split( '-', $sp_ecp->date );
$date = mktime(12, 0, 0, $month, 1, $year); // 1st day of month as unix stamp
$rawOffset = date("w", $date) - $startOfWeek;
$offset = ( $rawOffset date );?>
log($sp_ecp->daysOfWeekShort);
for( $n = $startOfWeek; $n daysOfWeek) + $startOfWeek; $n++ ) {
$dayOfWeek = ( $n >= 7 ) ? $n - 7 : $n;echo 'daysOfWeek[$dayOfWeek]) . '" abbr="' . $sp_ecp->daysOfWeek[$dayOfWeek] . '">' . $sp_ecp->daysOfWeekShort[$dayOfWeek] . '';
}
?><?php
// skip last month
for( $i = 1; $i <= $offset; $i++ ){
echo "";
}
// output this month
for( $day = 1; $day <= date("t", $date); $day++ ) {
if( ($day + $offset - 1) % 7 == 0 && $day != 1) {
echo "\n\t";
$rows++;
}// Var'ng up days, months and years
$current_day = date_i18n( 'd' );
$current_month = date_i18n( 'm' );
$current_year = date_i18n( 'Y' );if ( $current_month == $month && $current_year == $year) {
// Past, Present, Future class
if ($current_day == $day ) {
$ppf = ' tec-present';
} elseif ($current_day > $day) {
$ppf = ' tec-past';
} elseif ($current_day $month && $current_year == $year || $current_year > $year ) {
$ppf = ' tec-past';
} elseif ( $current_month < $month && $current_year == $year || $current_year < $year ) {
$ppf = ' tec-future';
} else { $ppf = false; }echo "" . display_day_title( $day, $monthView ) . "\n";
echo display_day( $day, $monthView );
echo "";
}
// skip next month
while( ($day + $offset) <= $rows * 7)
{
echo "";
$day++;
}
?><?php
function display_day_title( $day, $monthView ) {
$return = "";$return .= $day;
$return .= "";
for( $i = 0; $i < count( $monthView[$day] ); $i++ ) {
$post = $monthView[$day][$i];
setup_postdata( $post );
$return .= '' . get_the_title() . '';
}
$return .= '';
$return .= '';$return .= "";
return $return;
}function display_day( $day, $monthView ) {
global $post;
$output = '';
$posts_per_page = get_option( 'posts_per_page' );
for ( $i = 0; $i ID.'-'.$day;
$start = sp_get_start_date( $post->ID );
$end = sp_get_end_date( $post->ID );
$cost = sp_get_cost( $post->ID );
$address = sp_get_address( $post->ID );
$city = sp_get_city( $post->ID );
$state = sp_get_state( $post->ID );
$province = sp_get_province( $post->ID );
$country = sp_get_country( $post->ID );
?><div id='event_' >
<a href="">
<div id='tooltip_' class="tec-tooltip" style="display:none;">ID) || sp_is_multiday($post->ID) ) : ?>
<?php if ( !empty( $end ) && $start !== $end ) echo " – " . $end . ''; ?>
post_excerpt) : Events_Calendar_Pro::truncate(get_the_content(), 30); ?>
<?php
if( $i < count( $monthView[$day] ) - 1 ) {
echo "";
}
}
}
?>...
...
April 10, 2012 at 10:24 am #17780JonahParticipantThe plugin already does specific grid views based on category without you having to do anything else. You just go to http://your-url.com/events-slug/category/your-category-name/
If that doesn’t work for you and you still want to use page templates, you can. Basically I would suggest just copying the content of or including /wp-content/plugins/the-events-calendar/views/gridview.php into your page templates and then using the Gist code above to conditionally exclude categories based on the page template you are on (add a condition for the page template).
That should work.
April 17, 2012 at 9:04 am #17987nelsonMemberHave placed the function above >
/**
* Exclude a specific category from Events Grid View
*
* @author jkudish
* @uses pre_get_posts filter
* @param object $query the query object
* @return object $query the filtered object
*/
add_action( ‘pre_get_posts’, ‘exclude_events_category’ );
function exclude_events_category( $query ) {if ( $query->query_vars[‘post_type’] == TribeEvents::POSTTYPE && $query->query_vars[‘eventDisplay’] == ‘month’ && !is_tax(TribeEvents::TAXONOMY) && empty( $query->query_vars[‘suppress_filters’] ) ) {
$query->set( ‘tax_query’, array(
array(
‘taxonomy’ => TribeEvents::TAXONOMY,
‘field’ => ‘slug’,
‘terms’ => array(‘membersevents’),
‘operator’ => ‘IN’
)
) );
}
return $query;
}into a page with the gridview code in it and it is working perfectly by showing only category X events…. Until selecting the next or prior month – then the calendar reverts back to ALL categories of events. Looking to figure how to carry the “show only this category” along with the change in month. Even choosing event list reverts back to show all events.
April 18, 2012 at 10:17 am #18042JonahParticipantHey Nelson, this works fine for me in the regular calendar page but there might be something messing it up on a regular WP page. You may have to adjust the query to account for this but this is not something we can help you out with. Good luck!
April 24, 2012 at 2:18 pm #18248rudeetoursMemberJonah,
In reference to your post on 4/10, can you give a little more instruction please. I’ve got four templates for four categories. I now need to eliminate three non-active categories for each template. I’m not sure what I should put in my template and where.
I’m studying this and am obviously missing something.
https://theeventscalendar.com/support/documentation/the-events-calendar-template-tags-general-functions/#functiontribe_meta_event_category_name -
AuthorPosts
- The topic ‘Gridview Based On Category’ is closed to new replies.