July 12, 2017
<?php $tax_slug = get_query_var( 'taxonomy_category' ); ?>
Comes in handy if you’re working with custom post types, or external plugin archive pages.
I’ve used this with Tribe Events Calendar to create custom menus to their category pages as follows:
<?php $tax_slug = get_query_var( 'tribe_events_cat' ); ?>
Setup menu:
<ul class="event_cats">
<?php $args = array(
'taxonomy' => 'tribe_events_cat',
'orderby' => 'name',
'order' => 'asc',
'hide_empty' => 1,
);
$directory_cats = get_categories($args);
foreach($directory_cats as $category) : setup_postdata($category);
$current = $category->slug; ?>
<li class="<?php if($current === $tax_slug) { echo 'active'; } ?>"><a href="<?php bloginfo('url'); ?>/events/category/<?php echo $category->slug; ?>"><?php echo $category->name; ?></a></li>
<?php endforeach; wp_reset_postdata(); ?>
</ul><!-- .event_cats -->