Skip to content

Instantly share code, notes, and snippets.

@hchouhan
Created August 19, 2013 20:04
Show Gist options
  • Save hchouhan/6273438 to your computer and use it in GitHub Desktop.
Save hchouhan/6273438 to your computer and use it in GitHub Desktop.
Get Link to just 1 category in which the current post/product is in. dot_browse_product_cat()
<?php
// get taxonomies terms links
function dot_browse_product_cat() {
global $post, $post_id;
// get post by post id
$post = &get_post($post->ID);
// get post type by post
$post_type = $post->post_type;
// get post type taxonomies
$taxonomies = get_object_taxonomies($post_type);
foreach ($taxonomies as $taxonomy) {
// get the terms related to post
$terms = get_the_terms( $post->ID, $taxonomy );
if ( !empty( $terms ) ) {
$out = array();
foreach ( $terms as $term )
$out[] = '<a class="browse" href="' .get_term_link($term->slug, $taxonomy) .'"><i class="icon-th-large"></i> Browse '.$term->name.'</a>';
//$return = join( ', ', $out );
$return = $out[0];
}
}
return $return;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment