1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to set a link to the_post_thumbnail?

Discussion in 'WordPress' started by Divvy, Oct 12, 2015.

  1. #1
    Hello guys,

    I'm trying to insert link to my thumbnail images, but I'm stuck, can someone please help me?

    My code is:

    
    <?php if(has_post_thumbnail()) :
    the_post_thumbnail( 'full' );
    else : ?>
    
    PHP:
    Thank you for help!

    Kind regards
     
    Divvy, Oct 12, 2015 IP
  2. Divvy

    Divvy Well-Known Member

    Messages:
    781
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    After reading this url:
    https://codex.wordpress.org/Function_Reference/the_post_thumbnail

    I notice this solution:
    <?php if ( has_post_thumbnail() ) : ?>
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    <?php the_post_thumbnail(); ?>
    </a>
    <?php endif; ?>
    PHP:
    But my php knowledge is very very poor, and I dont know how can I edit my code:

    <?php if(has_post_thumbnail()) :
    the_post_thumbnail( 'full' );
    else : ?>
    PHP:
    As I can see, I need to put the_post_thumbnail( 'full' ); inside the a tag, but how? Any ideas? :)

    Thanks!
     
    Divvy, Oct 12, 2015 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    I think you should be able to just replace the code you had, with the one you pasted. That should do the trick.
     
    PoPSiCLe, Oct 12, 2015 IP
  4. Divvy

    Divvy Well-Known Member

    Messages:
    781
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #4
    Hey PoPSiCLe, thank you for your reply :)

    But where I put the else?

    This is my full code:

    <?php if(has_post_thumbnail()) :
    the_post_thumbnail( 'full' );
    else : ?>
    <img class="attachment-full wp-post-image" src="<?php bloginfo('template_url'); ?>/images/sample450.jpg" />
    <?php endif; ?>
    PHP:
    Thanks once again
     
    Divvy, Oct 13, 2015 IP
  5. Divvy

    Divvy Well-Known Member

    Messages:
    781
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #5
    Problem solved, thank you anyway my friend :)
     
    Divvy, Oct 13, 2015 IP