Created
July 31, 2017 23:09
-
-
Save KZeni/05b8e0069ab60924267bd32b2343c615 to your computer and use it in GitHub Desktop.
Add hierarchal support to the categories legend from The Events Calendar Category Colors WordPress plugin (as mentioned at https://github.com/afragen/the-events-calendar-category-colors/issues/83)
This file contains 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 | |
namespace Fragen\Category_Colors; | |
use Tribe__Events__Main; | |
$teccc = Main::instance(); | |
$show_hidden = false; | |
$options = get_option( 'teccc_options' ); | |
if ( isset( $options['show_ignored_cats_legend'] ) ){ | |
$show_hidden = true; | |
} | |
?> | |
<div id="legend_box" class="teccc-legend"> | |
<?php | |
$taxonomies = array('tribe_events_cat'); | |
$args = array( | |
'hide_empty' => false, | |
'fields' => 'all', | |
'parent' => 0, | |
'hierarchical' => true, | |
'child_of' => 0, | |
); | |
$terms = get_terms($taxonomies, $args); | |
?> | |
<?php | |
$ignored_term_slugs = array(); | |
foreach ( $teccc->ignored_terms as $ignored_term ){ | |
array_push($ignored_term_slugs,$ignored_term[0]); | |
} | |
?> | |
<ul id="legend" class="hierarchical"> | |
<?php foreach ( $terms as $term ): ?> | |
<?php if(in_array($term->slug,$ignored_term_slugs)): ?> | |
<?php if($show_hidden): ?> | |
<li class="teccc-hidden-category"><a href="<?php echo get_term_link($term->term_id); ?>"><?php echo $term->name; ?></a><input type="hidden" value="<?php echo $term->slug; ?>" /></li> | |
<?php endif; ?> | |
<?php else: ?> | |
<li id="category-<?php echo $term->term_id; ?>" class="tribe-events-category-<?php echo $term->slug; ?> tribe-events-category-<?php echo $term->term_id; ?>"><a href="<?php echo get_term_link($term->term_id); ?>"><?php echo $term->name; ?></a><input type="hidden" value="<?php echo $term->slug; ?>" /> | |
<?php | |
$subterms = get_terms($taxonomies, array( | |
'parent' => $term->term_id, | |
'hide_empty' => true | |
)); | |
?> | |
<ul> | |
<?php foreach ( $subterms as $subterm ): ?> | |
<?php if(in_array($subterm->slug,$ignored_term_slugs)): ?> | |
<?php if($show_hidden): ?> | |
<li class="teccc-hidden-category"><a href="<?php echo get_term_link($subterm->term_id); ?>"><?php echo $subterm->name; ?></a><input type="hidden" value="<?php echo $subterm->slug; ?>" /></li> | |
<?php endif; ?> | |
<?php else: ?> | |
<li id="category-<?php echo $subterm->term_id; ?>" class="tribe-events-category-<?php echo $subterm->slug; ?> tribe-events-category-<?php echo $subterm->term_id; ?>"><a href="<?php echo get_term_link($subterm->term_id); ?>"><?php echo $subterm->name; ?></a><input type="hidden" value="<?php echo $subterm->slug; ?>" /></li><!-- #category-<?php echo $subterm->term_id; ?> --> | |
<?php endif; ?> | |
<?php endforeach; ?> | |
</ul> | |
</li><!-- #category-<?php echo $term->term_id; ?> --> | |
<?php endif; ?> | |
<?php endforeach; ?> | |
</ul><!-- #legend --> | |
</div><!-- #legend_box --> |
This file contains 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
#tribe-events #legend.hierarchical { margin:1em 0; padding:0; } | |
#tribe-events #legend.hierarchical > li { display:block; float:none; text-align:left; } | |
#tribe-events #legend.hierarchical ul { margin:1em 0 0; padding:0; list-style:none; } | |
#tribe-events #legend.hierarchical li { margin:0.1em 0; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment