4

Almost all themes display categories (with its permalink) by default. I am looking for similar type of code to add in my theme. From where can I get it? To create custom taxonomies, I'm using More Taxonomies plugin.

13

The easiest way to list terms of custom taxonomy and display them would be to use

 <?php get_the_term_list( $id, $taxonomy, $before, $sep, $after ) ?> 

For example in the loop, my custom taxonomy is 'jobs' list as li

 <ul><?php echo get_the_term_list( $post->ID, 'jobs', '<li class="jobs_item">', ', ', '</li>' ) ?></ul>
  • I was able to display the items this way: <code><ul><?php echo get_the_term_list( $post->ID, 'jobs', '<li class="types_item">', '</li><li class="jobs_item">', '' ) ?></ul></code> – Diana Jan 1 '17 at 2:37
8

None of the code on this page worked, but the example from the wordpress site did:

<?php echo get_the_term_list( $post->ID, 'people', 'People: ', ', ', '' ); ?> 

I got it from http://codex.wordpress.org/Function_Reference/get_the_term_list

Hope it helps other lost souls who would like to display the current post taxonomies :)

1

Check this out. it worked for me. i have a taxonomy named 'stores', and i wanted to display 2 taxonmies from it.

<?php
    $taxonomy = 'stores';
    $args1=array(
        'include'=> array(12,30)
        );

    $terms = get_terms('stores',$args1 );
    echo '<ul>';


    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, 'stores' );
        if( is_wp_error( $term_link ) )
            continue;
        //We successfully got a link. Print it out.


        echo '<li><a href="' . $term_link . '">' . $term->name . '</a></li>';
    }
    echo '</ul>';
    ?>

Not the answer you're looking for? Browse other questions tagged or ask your own question.