• Resolved mrwolf2727

    (@mrwolf2727)


    I would think this would be easy, but I am having issues finding the right solution….

    My code is

    <?php the_post_thumbnail(array(200,150)); ?>

    However, it doesn’t make the thumbnail clickable. I want to be able to click the thumbnail and have it take me to the attachments.php template to show the bigger version.

    I tried

    <a href="<?php post_permalink() ?>"><?php the_post_thumbnail(array(200,150)); ?></a>

    and

    <a href="<?php wp_get_attachment_url(get_post_thumbnail_id()) ?>"><?php the_post_thumbnail(array(200,150)); ?></a>

    and still not yielding the results I am looking for. Even changed the “Link To” field in the admin side of the thumbnail and nothing.

    Any help?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mrwolf2727

    (@mrwolf2727)

    UPDATE: I found the get_attachment_link() function which should take me to the attachment.php page. However, nothing is returning from the function.

    Here is the code that I am using:

    <a href="<?php get_attachment_link(get_post_thumbnail_id($post->ID)) ?>"><?php the_post_thumbnail(array(200,150)); ?></a>
    <?php the_post_thumbnail_caption(); ?>
    <?php echo get_attachment_link(get_post_thumbnail_id($post->ID));?>

    The first get_attachment_link() outputs nothing, but the second one outputs the link that I want to use. I am assuming the_post_thumbnail() loads $post->ID, so how do I preload $post->ID before calling to the thumbnail?

    Thread Starter mrwolf2727

    (@mrwolf2727)

    … that damn “echo” statement.

    Boy do I feel sheepish. In case anyone needs the right code in the future…

    <a href="<?php echo get_attachment_link(get_post_thumbnail_id($post->ID)) ?>">
    <?php the_post_thumbnail(array(200,150)); ?></a>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘linking a the_post_thumbnail() result’ is closed to new replies.