Display correct breadcrumb on term taxonomy page

This commit is contained in:
Fabiano Alencar 2019-03-13 19:21:53 -03:00
parent 663d674c2f
commit d035cc6bab
1 changed files with 27 additions and 3 deletions

View File

@ -62,11 +62,35 @@ function tainacan_interface_the_breadcrumb() {
} elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) { } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
$post_type = get_post_type_object(get_post_type()); $post_type = get_post_type_object(get_post_type());
if(!is_page() && get_post_type() != 'tainacan-collection') { if(is_tax()) {
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$taxonomy = get_taxonomy( $term->taxonomy );
echo '<a href="'.site_url($taxonomy->rewrite['slug']).'">'; _e( 'Taxonomy: ', 'tainacan-interface' ); echo $taxonomy->labels->name; echo '</a>&nbsp;' . $delimiter . '&nbsp;';
// 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 '<a href="'.$url.'">'.$item->name.'</a>';
endforeach;
endif;
// Display the current term in the breadcrumb
echo $before . $term->name . $after;
} elseif(!is_tax() && get_post_type() != 'tainacan-collection') {
echo '<a href="'. esc_url(get_post_type_archive_link('tainacan-collection')) .'">'; _e( 'Collections', 'tainacan-interface' ); echo '</a>&nbsp;' . $delimiter . '&nbsp;'; echo '<a href="'. esc_url(get_post_type_archive_link('tainacan-collection')) .'">'; _e( 'Collections', 'tainacan-interface' ); echo '</a>&nbsp;' . $delimiter . '&nbsp;';
}
echo $before . $post_type->labels->singular_name . $after;
echo $before . $post_type->labels->singular_name . $after;
} else {
echo $before . $post_type->labels->singular_name . $after;
}
} elseif ( is_attachment() ) { } elseif ( is_attachment() ) {
$parent = get_post($post->post_parent); $parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID); $cat = $cat[0]; $cat = get_the_category($parent->ID); $cat = $cat[0];