jcadima
12/17/2017 - 6:36 PM

Breadcrumbs for single item in custom post type with taxonomy


<?php
// template name:  single-recipesindex.php
// URL: http://165.227.91.177/index.php/recipesindex/test-9/
// custom post type: recipesindex
// taxonomy: recipes


global $post;

/*
echo '<pre>' ;
print_r($post) ;
echo '</pre>';
*/

$category = get_the_category( $post->ID );
// echo '<h2>POST ID: ' . $post->ID . '</h2>' ;

// get single category term for this taxonomy
$terms = get_the_terms( $post->ID , 'recipes' );
echo 'Taxonomy Category: ' .  $terms[0]->name ;

/*
echo '<pre>' ;
print_r($terms) ;
echo '</pre>';
*/


// Get all terms(categories) in this taxonomy
//foreach ( $terms as $term ) {
//	echo $term->name;
//}


?>


<div id="recipes_breadcrumbs">
	<a href="<?php echo site_url(); ?>/index.php/recipes/">RECIPES</a> > <a href="<?php echo site_url() .'/index.php/recipes/' . $terms[0]->slug .'/' ;   ?>"><?php echo $terms[0]->name ; ?></a> > <?php echo $post->post_title; ?>
</div>


OUTPUT:

RECIPES > Drinks & Cocktails > Recipe test 9