Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to keep this category title on my pages, but I don't want it to be a link.

<?php echo get_the_term_list( get_the_ID(), 'portfolio_cats', ' ', ' , ', ' '); ?>

Can anyone help? Thanks

share|improve this question
    
How are you displaying the link on the page? Also move the code into a proper box for readability. –  Joshua May 22 '12 at 4:30
add comment

2 Answers

up vote 1 down vote accepted

You could use get_the_terms() and wp_sprintf_l():

function wpse_52878_term_list( $args = array() )
{
    $default = array (
        'id'               => get_the_ID(),
        'taxonomy'         => 'post_tag',
        'before'           => '',
        'after'            => '',
    );

    $options = array_merge( $default, $args );
    $terms   = get_the_terms( $options['id'], $options['taxonomy'] );
    $list    = array();

    foreach ( $terms as $term )
    {
        $list[] = $term->name;
    }
    return $options['before'] . wp_sprintf_l( '%l', $list ) . $options['after'];
}

echo wpse_52878_term_list( array ( 'id' => get_the_ID(), 'taxonomy' => 'portfolio_cats' ) );

Another option:

echo wp_strip_all_tags( 
    get_the_term_list( get_the_ID(), 'portfolio_cats', ' ', ' , ', ' ') 
);
share|improve this answer
    
Thank you so much. You just saved me a whole lot of time and stress! –  Toronto May 22 '12 at 14:22
add comment

Why not use this?

<?php
$portfolio_cats = wp_get_object_terms(get_the_ID(), 'portfolio_cats', array('fields' => 'names'));
if(!empty($portfolio_cats)){
    if(!is_wp_error( $portfolio_cats )){
        echo '<ul>';
        foreach($portfolio_cats as $term){
            echo '<li>'.$term->name'</li>'; 
        }
        echo '</ul>';
    }
}

Try a print_r with the returned array to see the contents.

share|improve this answer
    
@joshua The Code is being used to display the category as the page header. However I don't want it to link back to a page containing all of the category items. currently it displays like this: <h1><a href="../portfolio-category/branding/"rel="tag"> Branding</a></h1> –  Toronto May 22 '12 at 5:41
    
@joshua Sorry I'm not sure how to put the code in a box. <?php echo get_the_term_list( get_the_ID(), 'portfolio_cats', ' ', ' , ', ' ') ?> –  Toronto May 22 '12 at 5:42
    
You should use get_the_terms instead of wp_get_object_terms. wp_get_object_terms bypasses WordPress' caching, and essentially means you query the database with every call. –  Stephen Harris May 22 '12 at 12:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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