Hi everyone,
I just installed The Events Calendar, and so before I add my comment, I just want to say that I tried out 5-10 different calendar plugins, and this one was by far the best, but it does need 3 crucial things before I can fully commit to it:
1. Recurring events.
2. Real (sub)categories and filters.
3. Export to iCal/gCal.
Now, back to how I got a makeshift categories system to work. Here was my temporary solution: First, I created several subcategories under Events, which you select (only 1 subcategory for each event) when you go to create an Event, that way each event is marked under “Events,” and a corresponding subcategory. Or, alternatively, no subcategory can be selected.
Next, I corrected a small bug in /views/gridview-day.php:
<?php
foreach((get_the_category()) as $category) {
echo 'cat_' . $category->category_nicename . ' ';
}
?>
The old file has the actual *name* of the category, which–if the subcategory has spaces in it–just won’t work. Plus, using the nicename just seems like a better idea. Anyhow, the latest version of “The Events Calendar” assigns each event in the calendar a CSS element, so I wrote the following in my header.php file (please note that I have my “Events” category ID as 4, so that will need to change for each specific context in which this code is used):
<?php
// if a category view see if category is a 'direct child' of cat4
if ( is_category() ) {
$cat = get_query_var('cat');
$args = array(
'include' => $cat,
'hide_empty' => 0
);
$categories = get_categories($args);
if ( ($categories[0]->category_parent == 4) ) {
foreach((get_the_category()) as $category) {
if ($category->cat_ID != 4) {
echo "\t\t\t<style type='text/css'>\n";
echo "\t\t\t\t.tec-calendar td .tec-event {\n";
echo "\t\t\t\t\tdisplay: none;\n";
echo "\t\t\t\t}\n\n";
echo "\t\t\t\tdiv.cat_" . $category->category_nicename . " {\n";
echo "\t\t\t\t\tdisplay: block !important;\n";
echo "\t\t\t\t}\n";
echo "\t\t\t</style>\n";
}
}
}
}
?>
What this code does is detect if the current page being viewed is a subcategory of the Events category (so, the permalink URL might look something like /caetgory/events/subcategory/). If a subcategory of events is being viewed, the CSS is set to hide all events, and then display only the ones that match the nicename of the current category.
Since it’s outputting the style tags, it should be placed in the header’s <head>
tag.
It’s kind of a dumb and simplistic trick, since all it’s doing is visually hiding things, but it gets the job done, plus the RSS feeds still give the correct corresponding data, since it relies on WordPress’s categories taxonomy architecture.