Skip to content

Instantly share code, notes, and snippets.

@stephanieleary
Last active August 29, 2015 14:15
Show Gist options
  • Save stephanieleary/1ade0061e5f1a2b1b3fd to your computer and use it in GitHub Desktop.
Save stephanieleary/1ade0061e5f1a2b1b3fd to your computer and use it in GitHub Desktop.
category.php or taxonomy.php for deep hierarchies
<?php get_header(); ?>
<div id="container">
<div id="content" role="main">
<?php the_archive_title( '<h1 class="page-title">', '</h1>' ); ?>
<?php the_archive_description( '<div class="term-description">', '</div>' ); ?>
<?php
// Find out if this term has child terms
$object = get_queried_object();
$termchildren = get_term_children( $object->term_id, $object->taxonomy );
if ( !empty($termchildren) ) {
// It does! Print them as a linked list
echo '<ul class="term-navigation">';
foreach ( $termchildren as $child ) {
$term = get_term_by( 'id', $child, $object->taxonomy );
echo '<li><a href="' . get_term_link( $term->term_id, $term->taxonomy ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
}
else {
// It does not. Print the posts as usual.
get_template_part( 'loop', 'category' );
}
?>
</div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment