Customize Content on The Event Calendar Category Archives

As much as I LOVE Modern Tribe’s “The Events Calendar” plugin, theming with it can be a bit tricky. It is such an advanced plugin with so much functionality that sometimes relatively basic tasks can become difficult. The normal route of creating page templates or archive templates in your child theme simply doesn’t work all that well with The Events Calendar in some cases.

Luckily, they have outstanding support and very in-depth documentation!

I was recently tasked with adding custom descriptions to the top of each category archive page for categories assigned to events. These descriptions needed to show across both the “List” and “Calendar” views (which were the only views being uses” and needed to be simple for the end user to edit. Luckily, this one wasn’t too difficult!

First, we need to ensure that the changes are being made in the correct way to the correct page template. In this case we’ll need the following files from The Events Calendar plugin:

  • list.php
  • month.php

Both of these were copied from the plugin’s ‘/src/views’ directory in to the child theme’s ‘/tribe-events’ folder, which is where we’ll save our modified templates.

Next I used ACF (Adavnced Custom Fields) to create a WYSIWYG field for each category and set it on an options page that I am using for this particular theme. Using this technique will allow the end user to easily modify the content of each category description without needing to delve in to the code. There are plenty of tutorials out there for creating ACF fields and using options page, so we won’t get in to that here.

Finally, we’ll add the snippet below to both the list.php and month.php files.

<?php // get values for all ACF fields based on whatever you created
$cat1_description = get_field( 'cat1_description', 'option' );
$cat2_description = get_field( 'cat2_description', 'option' );

// Conditionally display the custom field if user is on category archive for said category
<?php if( is_tax( 'tribe_events_cat', 'category1_slug' ) && $cat1_description ) : ?>
	<?php echo $cat1_description; ?>
<?php elseif( is_tax( 'tribe_events_cat', 'category2_slug' ) && $cat2_description ) : ?>
	<?php echo $cat2_description; ?>
<?php endif; ?>

You’ll see the first thing we do is set variables for the custom ACF Fields that have been created. Then we use the conditional is_tax() to make sure we are on the archive page for the tribe_events_cat taxonomy and set the category as the second parameter to narrow it down to the taxonomy archive for that specific term.

We also check to ensure there is a description present by including && $cat1_description. This ensures that if a category is left blank on the options page, it will not display anything on the front end of the site.

And that’s all there is to it!

Get New Posts in Your Inbox

This field is for validation purposes and should be left unchanged.

About Matt Whiteley

Matt has been building bespoke WordPress websites for over 10 years specializing in the Genesis Framework. He integrates Advanced Custom Fields heavily in all builds, especially with the new Gutenberg Block Editor, allowing clients to easily modify all aspects of the their website with ease.

He works with a wide variety of small businesses and agencies across the country providing development services as well as hosting and maintenance. When he isn't coding he enjoys spending time with his wife and two children, golfing and playing poker.

Reader Interactions

Leave a Reply

Your email address will not be published.