• I created a custom taxonomy. This works well and I wanted to display the chosen tags in post-meta just like “tags” and “category”.

    With the following code I managed this:

    <?php
    $terms = get_terms('mytax');
    echo '<b>Special tags </b>';
    foreach ($terms as $term) {
        //Always check if it's an error before continuing. get_term_link() can be finicky sometimes
        $term_link = get_term_link( $term, 'mytax' );
        if( is_wp_error( $term_link ) )
            continue;
        //We successfully got a link. Print it out.
        echo '<a href="' . $term_link . '">' . $term->name . '</a>&nbsp;';
    }
    
    ?>

    Source: here

    But I found out that if I clicked on a custom taxonomy
    http://www.mysite.de/blog/mytax/xyz
    you already support the list of custom taxonomies in the post overview site in the loop.

    How can I use this function myself??
    Reason: Your function is a bit nicer because you output the name of the custom taxonomy and set “and” between the last and 2nd last tag… 😉

    Thanks for some advice,
    Enno

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Enno

    (@ewx)

    Sorry, this is the right code (taken from the worpdress codex)

    $taxonomy = 'mytax';
    
    // get the term IDs assigned to post.
    $post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
    // separator between links
    $separator = ', ';
    
    if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) {
    	echo '<b>works on Release</b>&nbsp;';
    	$term_ids = implode( ',' , $post_terms );
    	$terms = wp_list_categories( 'title_li=&style=none&echo=0&taxonomy=' . $taxonomy . '&include=' . $term_ids );
    	$terms = rtrim( trim( str_replace( '<br />',  $separator, $terms ) ), $separator );
    
    	// display post categories
    	echo  $terms;
    }
    ?>

    the previous posted code displays all taxonmies.

    Theme Author Richie KS

    (@rkcorp)

    is it this one found in lib/templates/post-meta.php?
    <?php echo the_taxonomies('before=<span class="post-category"><i class="icon-file"></i>&after=</span>'); ?>

    Thread Starter Enno

    (@ewx)

    Yes, it is! Thanks!
    Will I be able to restrict the call for only ONE specific taxonomy?

    By the way? Is this a standard WP function?
    maybe expanded by you?

    there is a little fault: It displays the tags like this:

    tag1, tag2, and tag3

    the comma before “and” is too much… 😉

    Theme Author Richie KS

    (@rkcorp)

    not sure, this is wp default taxonomy functions, check its functions paramenter in codex.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display tags of custom taxonomy’ is closed to new replies.