Skip to content

Instantly share code, notes, and snippets.

@mattradford
Created August 19, 2015 08:55
Show Gist options
  • Save mattradford/7825ff84c7d3e32b381d to your computer and use it in GitHub Desktop.
Save mattradford/7825ff84c7d3e32b381d to your computer and use it in GitHub Desktop.
Tax terms subnav
<nav class="subnav">
<?php
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$args = array(
'hide_empty' => false,
'orderby' => 'slug'
);
$tax_terms = get_terms($taxonomy,$args);
if (!empty( $tax_terms )) :
echo '<ul>';
foreach( $tax_terms as $term ) {
if ($term->term_id == $term_id) :
echo '<li class="active"><a href="' . get_term_link( $term->slug, $taxonomy ) . '">' . $term->name . '</a></li>';
else :
echo '<li><a href="' . get_term_link( $term->slug, $taxonomy ) . '">' . $term->name . '</a></li>';
endif;
}
echo '</ul>';
endif;
?>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment