Forums

Making POST THUMBNAIL link to post (13 posts)

  1. DocEroc
    Member
    Posted 2 years ago #

    I may be overlooking something, but why does the POST THUMBNAIL not "automagically" link to either the post or to a full size image of the thumbnail?

    Is there something I am missing? Can/how/where can I put in maybe some php to make the thumbnail do this?

  2. DocEroc
    Member
    Posted 2 years ago #

    Ok, I have started this on my own.
    For the ARCHIVES page, you would use this:

    <div class="entry">
    <a href="<?php the_permalink() ?>"><?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { the_post_thumbnail(array(200,160), array("class" => "alignleft post_thumbnail")); } ?></a>

    Placing the ANCHOR before the thumbnail and then closing the anchor just after.
    So for the other pages, basically the same thing, so I will follow up...

  3. DocEroc
    Member
    Posted 2 years ago #

    <a href="<?php the_permalink() ?>">

    That is the same process for the main index template page to link that image to the post as well.

    Still looking for the code to pull the full-size image of the thumbnail

  4. foronca
    Member
    Posted 2 years ago #

    Hi, I had a similar question, this is how i managed the full-size image question :

    <?php $thumb_id = get_post_thumbnail_id( $post->ID );?>
    <?php $image = wp_get_attachment_image_src( $thumb_id,'full' ); ?>
    <?php echo $image[0]; ?>

    In the first step i get the thumbnail Id
    The second allows me to get the image src info (cf. wp_get_attachment_image_src) in full size.
    the last echoes the first value returned wich is the url.

  5. mrfletch
    Member
    Posted 2 years ago #

    Thank you foronca, this is exactly what I needed. This should have been built into post-thumbnails when it was release. Can't believe they overlooked it.

    -Paul

  6. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    They didn't. You can set the size of the post thumb and even create custom thumbs using set_post_thumbnail_size() and add_image_size() respectively.

  7. felixo
    Member
    Posted 2 years ago #

    But there seems to be no way to have the thumbnail link to the_permalink. Or am I oevrlooking something. It seems obvious to me that the thumbnail should link to the_permalink. On every page with excerpts. Is there a "standard" way to accomplish this?

  8. mghch
    Member
    Posted 2 years ago #

    Finally got it working and is reducing my bounce rate already!

    It works really well with the Cover WP theme

  9. jcaruso
    Member
    Posted 1 year ago #

    What???!!! How did you guys do this??! I can't figure it out! Help!

  10. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    // THIS LINKS THE THUMBNAIL TO THE POST PERMALINK
    
    add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );
    
    function my_post_image_html( $html, $post_id, $post_image_id ) {
    
    	$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>';
    
    	return $html;
    }

    in functions.php links all post thumbnails to the permalink

  11. Andy Smith
    Member
    Posted 1 year ago #

    ....Rev. Voodoo

    Fantastic! thanks for sharing...

  12. ant1mazr
    Member
    Posted 1 year ago #

    @ Rev. Voodoo
    thanks, sharp tip !

  13. bwaw
    Member
    Posted 1 year ago #

    @ Rev. Voodoo

    Thanks, finally got the featured images linked to their posts! Although the code works fine, I can't say I completely understand it. Could you (or anyone else) please tell me what the numbers 10 and 3 stand for?

    Thanks very much in advance.

Topic Closed

This topic has been closed to new replies.

About this Topic