hchouhan
8/19/2013 - 8:04 PM

Get Link to just 1 category in which the current post/product is in. dot_browse_product_cat()

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;
}
?>