function ubik_places_ancestors($taxonomy = 'places', $depth = 2, $sep = ', ') { // Initialize $output = ''; $places = array(); // Get term ID; we only need one global $post; $terms = get_the_terms($post->ID, $taxonomy); $term = $terms[0]; // Only proceed if this term shows inheritance if (!empty($term->parent)) { // The grunt work $ancestors = ubik_terms_ancestors($term->term_id, $taxonomy); // Ready to roll if (!empty($ancestors) && count($ancestors) > 1) { // Remove basal term, limit depth, and reverse (as is the custom for displaying places) $ancestors = array_reverse(array_slice(array_slice($ancestors, 0, -1), 0, $depth)); // Loop through all ancestors and create links if (!empty($ancestors)) { foreach ($ancestors as $ancestor) { $place = get_term_by('id', $ancestor, $taxonomy); $places[] = '<a href="' . get_term_link($place->term_id, $taxonomy) . '" rel="tag">' . $place->name . '</a>'; } // Assemble output if (!empty($places)) { $output = implode($sep, $places); } } } } return $output; }
function ubik_terms_breadcrumbs($term = '', $taxonomy = '', $before = '<nav class="breadcrumbs" itemprop="breadcrumb"><ul><li>', $join = '</li><li>', $after = '</li></ul></nav>') { // Initialize $output = ''; $ancestors = ubik_terms_ancestors($term, $taxonomy); // Got something? if (!empty($ancestors)) { // For each parent, create a list item foreach ($ancestors as $ancestor) { $item = get_term_by('id', $ancestor, $taxonomy); $link = get_term_link($ancestor, $taxonomy); $crumbs[] = '<a href="' . $link . '">' . $item->name . '</a>'; } // Got something? Wrap it up! if (!empty($crumbs)) { $output = "\n" . $before . implode($join, $crumbs) . $after . "\n"; } } // Return what we've got return apply_filters('ubik_terms_breadcrumbs', $output); }