• Resolved needtakehave

    (@needtakehave)


    I created several taxonomies and custom metaboxes for my custom posts/templates. However, I’m having a problem with the linking. As you can see here – http://www.booksbytheton.xyz/blogtours/after-loving-you/ under CONNECT – the links aren’t linking correctly and I can’t see why. And before I erased it, the images weren’t either. The links for them (I was trying to link the images to a website) weren’t linking, they were showing up the same way, as a link right before the image, and again, I don’t know why since the coding itself looks okay but I must be missing something.

    This is the image code –

    <?php if (get_post_meta( $post->ID, 'cmb2_promo2' ) != '') { ?><p><center><a href="<?php echo get_the_term_list($post->ID, 'blogtour', true); ?>" target="_blank"><img src="<?php echo get_post_meta($post->ID, 'cmb2_promo2', true); ?>" alt="$tttitle" title="$tttitle" width="500" border="0"></a></center></p><?php } ?>

    These are the “connect” codes.

    <center><?php if (get_the_term_list( $post->ID, 'website' ) != '') { ?><a href="<?php echo get_the_term_list($post->ID, 'website', true); ?>" target="_blank">WWW</a><?php } ?>
    			<?php if (get_the_term_list( $post->ID, 'amazon' ) != '') { ?> | <a href="<?php echo get_the_term_list($post->ID, 'amazon', true); ?>" target="_blank">Amazon</a><?php } ?>
    			<?php if (get_the_term_list( $post->ID, 'facebook1' ) != '') { ?> | <a href="<?php echo get_the_term_list($post->ID, 'facebook1', true); ?>" target="_blank">Facebook</a><?php } ?>
    			<?php if (get_the_term_list( $post->ID, 'facebook2' ) != '') { ?> | <a href="<?php echo get_the_term_list($post->ID, 'facebook2', true); ?>" target="_blank">Facebook</a><?php } ?>
    			<?php if (get_the_term_list( $post->ID, 'goodreads' ) != '') { ?> | <a href="<?php echo get_the_term_list($post->ID, 'goodreads', true); ?>" target="_blank">Goodreads</a><?php } ?>
    			<?php if (get_the_term_list( $post->ID, 'instagram' ) != '') { ?> | <a href="<?php echo get_the_term_list($post->ID, 'instagram', true); ?>" target="_blank">Instagram</a><?php } ?>
    			<?php if (get_the_term_list( $post->ID, 'pinterest' ) != '') { ?> | <a href="<?php echo get_the_term_list($post->ID, 'pinterest', true); ?>" target="_blank">Pinterest</a><?php } ?>
    			<?php if (get_the_term_list( $post->ID, 'twitter' ) != '') { ?> | <a href="<?php echo get_the_term_list($post->ID, 'twitter', true); ?>" target="_blank">Twitter</a><?php } ?>
    			<?php if (get_the_term_list( $post->ID, 'news' ) != '') { ?> | <a href="<?php echo get_the_term_list($post->ID, 'news', true); ?>" target="_blank">News</a><?php } ?></center><br />
Viewing 1 replies (of 1 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Looks like you’re trying to do too much with get_the_term_list().

    From the codex page: “Returns an HTML string of taxonomy terms associated with a post and given taxonomy. Terms are linked to their respective term listing pages.”
    https://codex.wordpress.org/Function_Reference/get_the_term_list

    It’s not going to return a link to the term, it’s going to return some HTML markup as well. You’re trying to pass all that into an href attribute.

    From the examples on the codex page:

    This would return everything in the second code snippet below, complete <a> tags included:

    <?php echo get_the_term_list( $post->ID, 'people', 'People: ', ', ' ); ?>
    
    People: <a href="person1">Person 1</a>, <a href="person2">Person 2</a>, ...
    
Viewing 1 replies (of 1 total)

The topic ‘Codes Not Working Correctly’ is closed to new replies.