Created
November 18, 2014 14:19
-
-
Save DanBeckett/8d878be7255e6bcd079a to your computer and use it in GitHub Desktop.
List WordPress category terms, apply parent class to any terms with children
This file contains hidden or 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 | |
$terms = get_terms('category'); | |
if ( !empty( $terms ) && !is_wp_error( $terms ) ){ | |
foreach( get_terms( 'category', array( 'hide_empty' => false, 'parent' => 0 ) ) as $parent_term ) { | |
$term_children = get_term_children($parent_term->term_id, 'category'); ?> | |
<li class="term_item<?php echo ($term_children ? ' parent' : ''); ?>" data-hook="<?php echo $parent_term->slug; ?>"> | |
<a href="<?php echo home_url(); ?>/products/<?php echo $parent_term->slug; ?>"><?php echo $parent_term->name; ?></a> | |
</li> | |
<?php } | |
} ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment