How to set a link to the_post_thumbnail?

Status
Not open for further replies.

Divvy

Active Member
806
2009
18
0
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:
<?php if(has_post_thumbnail()) :the_post_thumbnail( 'full' );else : ?>

Thank you for help!


Kind regards

-----------------------
After reading this url:
https://codex.wordpress.org/Function_Reference/the_post_thumbnail

I notice this solution:
PHP:
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>

But my php knowledge is very very poor, and I dont know how can I edit my code:

PHP:
<?php if(has_post_thumbnail()) :
the_post_thumbnail( 'full' );
else : ?>

As I can see, I need to put the_post_thumbnail( 'full' ); inside the a tag, but how? Any ideas? :)

Thanks!
 
Last edited:
5 comments
Replace
PHP:
<?php if(has_post_thumbnail()) :the_post_thumbnail( 'full' );else : ?>

with

PHP:
<?php if ( has_post_thumbnail() ) : ?> 
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> 
<?php the_post_thumbnail('full'); ?> 
</a> 
<?php endif; ?>
 
Thank you for your replies :)

DejaVu, and where I put the else?

This is my full code:

PHP:
<?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; ?>

Thanks once again
 
Last edited:
PHP:
<?php if ( has_post_thumbnail() ) { ?> 
  <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> 
  <?php the_post_thumbnail('full'); ?> 
  </a> 
<?php } else { ?>
  // else code here
<?php } ?>
 
Status
Not open for further replies.
Back
Top