• I’m not a coder, but I do understand some code and have successfully modified a lot of it, but I just can’t wrap my head around this one. And it seems so easy. So, this is part of the code of a gallery page. Thing is, when I click on the picture, it links me to the permalink. I don’t want it to link me to the permalink, but to the featured image url. How can I do this? Can somebody PLEASE help. Here’s the code:

    <div <?php post_class("gallery-item isotope-item $term_list"); ?> >
    											<?php
    												$image_id = get_post_thumbnail_id();
    												global $gallery_image_size;
    												$featured_image = wp_get_attachment_image_src( $image_id, $gallery_image_size );
    											?>
    											<a href="<?php the_permalink(); ?>"><?php echo '<img src="'.$featured_image[0].'" alt="'.get_the_title().'">'; ?></a>
    											<?php
    											if ( $terms && !is_wp_error( $terms ) ):
    												$i = 0;
    												$count = count($terms);
    											endif;
    											?>
    									</div>
Viewing 4 replies - 1 through 4 (of 4 total)
  • That’s not the proper code. This code only displays the class for a <div> element , something along those lines:

    <div class=”post-123 attachment gallery-item isotope-item”>

    where 123 is the id of the attachment.

    You may find your answer here : http://codex.wordpress.org/Function_Reference/the_post_thumbnail
    under “Post Thumbnail Linking to Large Image Size”

    Thread Starter edinchez

    (@edinchez)

    I’m not sure if you noticed, but there’s more to the code than that <div> element. The format I pasted it in is wrong, and I’m sorry for that. Here’s the particular piece of code I need to change:

    <?php								$image_id = get_post_thumbnail_id();
    global $gallery_image_size;
    $featured_image = wp_get_attachment_image_src( $image_id, $gallery_image_size );
    ?>
    <a href="<?php the_permalink(); ?>"><?php echo '<img src="'.$featured_image[0].'" alt="'.get_the_title().'">'; ?></a>

    Especially this:

    <a href="<?php the_permalink(); ?>"><?php echo '<img src="'.$featured_image[0].'" alt="'.get_the_title().'">'; ?></a>

    I guess $gallery_image_size is a thumbnail size?
    You need to retrieve a thumbnail and a large image.

    <?php
    $image_id = get_post_thumbnail_id();
    global $gallery_image_size;
    $featured_image = wp_get_attachment_image_src( $image_id, 'large' );
    ?>
    
    <a href="<?php echo $featured_image[0]; ?>"><?php the_post_thumbnail($gallery_image_size); ?></a>

    Just make sure that $gallery_image_size is compliant to the parameters accepted by the_post_thumbnail()

    Thread Starter edinchez

    (@edinchez)

    Works perfectly! You are a life saver! Thank you very very much.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get featured image url and link to it’ is closed to new replies.