• Hi,

    I was wondering, when I make a new post with a featured image attached to it, I can make the image clickable with a url of my choice.
    So, now I want my featured posts on my frontpage to link directly to the url I’ve attached to my image (of that featured post)…
    Because right now people have got to click on the image, going to the post, and have to click again on that image to go to the site mentioned.

    Check my site to help visualize things a little; https://www.mtgfeeds.com – eg. featured post = mananation’s – when you click on the image while on the frontpage – you directly get redirected to mananation.com

    Anyone care to help me out here?

    I would be mighty grateful… ??

    Kind regards

Viewing 4 replies - 16 through 19 (of 19 total)
  • @dhebe – Im sure that doesnt work.

    @faberuna – the code goes in your page/post template.

    @resonant705 – Why are you using the_permalink() if you are wanting to link to the featured external link?

    Shouldnt your code read:

    <?php if(has_post_thumbnail()) {
     if($content = $post->post_content ) { ?>
      <a href="<?php $key="featured_external"; echo get_post_meta($post->ID, $key, true); ?>" title="<?php the_title(); ?>">
     <?php the_post_thumbnail('feat-loop2'); ?>
     </a>
     <?php } else { ?>
     <a href="<?php $key="featured_external"; echo get_post_meta($post->ID, $key, true); ?>" title="<?php the_title(); ?>">
     <?php the_post_thumbnail(); ?>
     </a>
     <?php } ?>
     <?php } ?>

    Is that what you mean as Im not quite sure I get your issue?

    Thanks for replying!
    I have a section that calls a certain cat to the page.
    I want to have the option of putting a external link on the featured thumbnail (and title) if there is no external link in the custom field then it uses the reg. post or page link.

    That isnt the logic you are currently using though.

    Whats this bit doing, is there other code you havent posted:
    if($content = $post->post_content ) { ?>

    Currently your code is saying:

    If post has a thumbnail display the thumbnail with a link to posts permalink

    else display a thumbnail with an external link.

    You ar enot using an argument to find it there is an external url or not, also you are not displaying any clickable link titles/text.

    So you are using the $custom variable to hold the external url using:
    $key="featured_external"; $custom = get_post_meta($post->ID, $key, true);

    You should use this for you if statement:

    if($custom != ""){
    <a href="<?php echo $custom; ?>" title="<?php the_title(); ?>">
     <?php the_post_thumbnail(); ?>
    </a>
    } else {
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
     <?php the_post_thumbnail(); ?>
    </a>
    }

    Can you do me a favor and simplify all this code-speak?
    a) I need to add something to a custom field. What code goes in the custom field.
    b) Now I need to add some code to the template itself. Where do I put it and what exactly am I putting?

Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘Featured Image Link’ is closed to new replies.