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'm currently using the below code for displaying standard post tags in a sidebar, given the current post has one associated with it. If not, no tag & accompanying headline, etc., should be displayed. Also, the usual /tags slug should be removed in the URLs, respectively. Again, my below code does that, which is exactly what I want.

However, how can I accomplish the same thing with a custom taxonomy of, say, "rivers"?

Your guidance is much appreciated as I've tried several things already, to no avail.

The current code (in use for standard post tags):

<?php
    $tags = get_the_tags();
    if ($tags) {
        echo '<h2>Holiday Regions</h2>
        <p class="rightP">';
            foreach ($tags as $tag) {
                echo '<a href="' . get_option('siteurl') . '/' . $tag->slug . '" title="' . sprintf( __( "Learn more about the %s" ), $tag->name ) . '"' . '>' . $tag->name.'</a><br />
        ';
                }
        echo '</p>';
        }
    ?>

For those who are in a similar situation, here's what did the trick—thanks to the hint from @Michael:

<?php
    $terms = get_the_terms( $post->ID, 'rivers' );
    if ($terms) {
        echo '<h2>Rivers</h2>
        <p class="rightP">';
            foreach ($terms as $term) {
                echo '<a href="' . get_option('siteurl') . '/' . $term->slug . '" title="' . sprintf( __( "Learn more about the %s" ), $term->name ) . '"' . '>' . $term->name.'</a><br />
        ';
                }
        echo '</p>';
        }
    ?>
share|improve this question
1  
have you looked into codex.wordpress.org/Function_Reference/get_the_terms –  Michael Oct 11 '11 at 13:04
    
Excuse me, I'm not a pro... Is this for listing a specific term? I want to list all custom tags that I gave any given post, if it's got one (ore more). –  Marcus Hochstadt Oct 11 '11 at 13:32
    
OK, got it @Michael! get_the_terms does the trick (incl. changing $tag to $term in my code example, etc.). Thank you! –  Marcus Hochstadt Oct 11 '11 at 14:02
    
great ;-) i'll add my comment as an answer, so the topic can be properly finished. –  Michael Oct 11 '11 at 14:36
    
@MarcusHochstadt I would recommend to use get_tag_link and get_term_link, codex.wordpress.org/Function_Reference/get_term_link –  Mamaduka Oct 11 '11 at 16:52
show 1 more comment

1 Answer

look into using get_the_terms()

share|improve this answer
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.