• I’m looking for something similar to get_the_term_list but in a way that doesn’t output the results as URLs.

    I would just like the actual term names for a specific taxonomy that are associated with the post.

    I’m all ears!

Viewing 8 replies - 16 through 23 (of 23 total)
  • I’d expect ..

    <ul>
    <?php get_the_term_list( $post->ID, 'taxonomy' , '<li>' , '</li><li>' , '</li>' ); ?>
    </ul>

    ..to work… ??

    Codex page is clear enough i think..

    <ul>
    <?php get_the_term_list( $post->ID, 'taxonomy' , '<li>' , '</li><li>' , '</li>' ); ?>
    </ul>

    How would you go about adding a class name that is the same as the taxonomy name, to each of those list items?

    Add it to the element in the code literally?

    <ul>
    <?php get_the_term_list( $post->ID, 'my_taxonomy' , '<li class="my_taxonomy">' , '</li><li class="my_taxonomy">' , '</li>' ); ?>
    </ul>

    Thanks for the speedy reply, not quite what i was after. I’m trying to create a class name for the value of each taxonomy.

    <ul>
    <?php get_the_term_list( $post->ID, 'colours' , '<li>' , '</li><li>' , '</li>' ); ?>
    </ul>

    Produces a list something like:

    • red
    • blue
    • green

    I want each list item to have a class that corresponds to the list value… eg red, blue or green

    Oh, you mean the term, beyond the scope of that particular function, the example i gave further up using get_terms would be suitable though.

    Something like..

    <?php
    $taxonomy = 'my_taxonomy';
    $terms = get_the_terms( $post->ID , $taxonomy );
    
    if ( empty( $terms ) ) :
    
    echo '<ul>';
    
    foreach ( $terms as $term ) {
    	$link = get_term_link( $term, $taxonomy );
    	if ( !is_wp_error( $link ) )
    		echo '<li class="' . $term->slug. '"><a href="' . $link . '" rel="tag">' . $term->name . '</a></li>';
    }
    
    echo '</ul>';
    
    endif;
    ?>

    Untested, but it should work..

    Ah perfect! Well almost, you were missing the ! in:

    if ( !empty( $terms ) ) :

    Thanks heaps, exactly what I was after ??

    Oops… ??

    Happy to help.. ??

    I am trying to do something like this. Instead of returning a list of all the categories within a custom taxonomy, I only want to return the first one. I have a portfolio page with ‘media’ as my custom taxonomy. I want to show the name of each category inside ‘media’ (identity, print, web) as a link to a category archive. Underneath the link will be thumbnails of the posts in that category.

    When I use the get_term_link inside the loop, it returns the link each time it shows a post. If I use it in its own seperate loop it returns the link like I want, but it returns it multiple times depending on the number of posts.

    <?php
    $post_type = 'Portfolio';
    $tax = 'media';
    $tax_terms = get_terms($tax);
    if ($tax_terms) {
    foreach ($tax_terms as $tax_term) {
    $args=array(
    'post_type' => $post_type,
    "$tax" => $tax_term->slug,
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts'=> 1
    );
    
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    
    $divName = $tax_term->name ;?>
    
    <div class="<?php echo $divName; ?>">
    
    <?php echo $tax_term->name. ' Projects ' ;

    This is what I’m using now to display the category name a single time. Is it possible to attach the link to this? Can get_term_link be used outside the loop, or modified to return only the first result?

Viewing 8 replies - 16 through 23 (of 23 total)
  • The topic ‘Trying to output a post’s terms (taxonomy) as text, not URLs’ is closed to new replies.