Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created October 30, 2011 05:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save billerickson/1325540 to your computer and use it in GitHub Desktop.
Save billerickson/1325540 to your computer and use it in GitHub Desktop.
Taxonomy Breadcrumb
<?php
/* Taxonomy Breadcrumb */
function be_taxonomy_breadcrumb() {
// Get the current term
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
// Create a list of all the term's parents
$parent = $term->parent;
while ($parent):
$parents[] = $parent;
$new_parent = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
$parent = $new_parent->parent;
endwhile;
if(!empty($parents)):
$parents = array_reverse($parents);
// For each parent, create a breadcrumb item
foreach ($parents as $parent):
$item = get_term_by( 'id', $parent, get_query_var( 'taxonomy' ));
$url = get_bloginfo('url').'/'.$item->taxonomy.'/'.$item->slug;
echo '<li><a href="'.$url.'">'.$item->name.'</a></li>';
endforeach;
endif;
// Display the current term in the breadcrumb
echo '<li>'.$term->name.'</li>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment