I have made a function for use in my breadcrumbs. The breadcrumb displays custom URL's for certain taxonomy categories. It works wonderfully, however, I need help if the post is filtered under multiple categories.
<?php
function customFruitBreadcrumbs() {
$terms = get_the_terms( $post->ID , 'fruit_category' );
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, 'fruit_category' );
if( is_wp_error( $term_link ) )
continue;
switch ($term->name) {
case "Spring":
echo '<a href="/fruits/spring-fruits/">Spring Fruits</a> » ';
break;
case "Summer":
echo '<a href="/fruits/summer-fruits/">Summer Fruits</a> » ';
break;
case "Autumn":
echo '<a href="/fruits/autumn-fruits/">Autumn Fruits</a> » ';
break;
case "Winter":
echo '<a href="/fruits/winter-fruits/">Winter Fruits</a> » ';
break;
default:
echo '';
}
}
}
?>
This function uses a switch statement to display the proper markup in my breadcrumbs. The problem arises when the post has 2+ categories (EG summer & spring).
How can I check the count of categories to place my switch statement if categories == 1? if > 1 category, I would just like to display:
echo '<a href="/fruits/">Fruits</a> » ';