• Hello,
    i want to list taxonomies/terms where some post belongs for example. I used this code

    <?php $terms = get_the_terms( $post->ID , 'pravilnici' ); foreach( $terms as $term ) {  print $term->name ;  unset($term); }?>

    It list terms in this manner term1term2term3 without space or , for example. Also its just text, its not a link to respective term.

    How can i achieve that?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello devmitrovics,

    Please replace your code with below code:

    $terms = get_the_terms( $post->ID , 'pravilnici' );
    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
        $count = count( $terms );
        $i = 0;
        $term_list = '<p>';
        foreach ( $terms as $term ) {
            $i++;
            $term_list .= '<a href="' . esc_url( get_term_link( $term ) ) . '" alt="' . esc_attr( sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name ) ) . '">' . $term->name . '</a>';
            if ( $count != $i ) {
                $term_list .= ' &middot; ';
            }
            else {
                $term_list .= '</p>';
            }
        }
        echo $term_list;
    }

    Thanks

    Thread Starter devmitrovics

    (@devmitrovics)

    Thank you a lot! Working like a charm

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List taxonomies with links’ is closed to new replies.