Forums

getting taxonomy link without the term (3 posts)

  1. jordas
    Member
    Posted 6 months ago #

    Hi,

    I am confused, I have seen so many 'solutions' to my problem but none of them seems to work for my specific situation. I have a taxonomy called project. Within the loop I am trying to get the link to the taxonomy the post is part of. It works fine with this:

    <?php the_terms( $post->ID, 'project', ' ', ', ', ' ' );?>

    but the problem with this line is that it outputs the taxonomy name with the link wrapped around it. But I want to use this link to wrap around an image that comes from the same post.

    So I don't want a whole list of links or a return of all the posts in that taxonomy or anything. I just want to link to that taxonomy with an image instead of the taxonomy term. The following obviously doesn't work, but what will?

    <a href="<?php the_terms( $post->ID, 'project', ' ', ', ', ' ' );?>"><img src="<?php echo $data[ 'portrait' ]; ?>"/></a>

    I hope anyone can help me.

    J

  2. jordas
    Member
    Posted 5 months ago #

    still have no solution, please anyone?

    I found this bit of code in the codex and changed it a bit. It outputs ALL the inputs of a taxonomy and with just taking some stuff out it outputs the list of URLs

    <?php $terms = get_terms('project');
    echo '<ul>';
    foreach ($terms as $term) {
        echo get_term_link($term->slug, 'project');
    }
    echo '</ul>';?>

    But it just won't work to change it in a way that only outputs the taxonomy linked to that specific post, putting it this way

    <?php the_terms( $post->ID, 'project', ' ', ', ', ' ' );
    echo '<ul>';
    foreach ($terms as $term) {
        echo get_term_link($term->slug, 'project');
    }
    echo '</ul>';?>

    only results in outputting the same as the first code, no URL but the full link (name+URL). It basically ignores part 2. Then I would think

    echo get_term_link ( $post->ID, 'project', ' ', ', ', ' ' )

    could maybe do it, but that just breaks the page...

    I hope you can help me, can you help me please?

  3. jordas
    Member
    Posted 5 months ago #

    Ow my god, I jus figured it out thanks to this link

    http://wordpress.org/support/topic/custom-taxonomies-getingt-rid-of-link-on-display?replies=13

    Thank you Mark for just explaining a simple basic which I overlooked. Forgot the word 'the'. Now this is the final thing:

    <?php get_the_terms( $post->ID, 'project', ' ', ', ', ' ' );
    foreach ($terms as $term) {
        echo get_term_link($term->slug, 'project');
    };?>

    How obvious!!

Reply

You must log in to post.

About this Topic