0

My WordPress site displays featured images at the top of each post. Here's the PHP code from post.php that generates the featured image.

<?php if ( current_theme_supports( 'get-the-image' ) ) get_the_image( array( 'meta_key' => 'Thumbnail', 'size' => 'single-thumbnail', 'link_to_post' => false, 'image_class' => 'featured', 'attachment' => false ) ); ?>

This code just outputs a standard <img> tag into the page. For example:

<img src="http://www.ericanastas.com/wp-content/uploads/2015/07/2015-04-10_190211-636x460.png" alt="Parkmerced Block 22 Geometry" class="single-thumbnail featured">

However, other images that I add to the content of a post show as a LightBox when clicked. Here's the HTML for one of these images.

<a href="http://www.ericanastas.com/wp-content/uploads/2015/07/2015-04-10_190211.png" rel="lightbox">
<img class="alignnone wp-image-2770 size-single-thumbnail" src="http://www.ericanastas.com/wp-content/uploads/2015/07/2015-04-10_190211-636x460.png" alt="2015-04-10_190211" width="636" height="460" style="opacity: 1;">
</a>

I would like to add the same LightBox functionality to the featured image at the top of each post. I'm familiar with HTML/CSS/JavaScript but am very new to PHP and WordPress. Can someone help me figure out what code I need to add to get this to work?

closed as off-topic by Nicolai, Brad Dalton, Howdy_McGee, Mark Kaplun, TheDeadMedic Jul 19 '15 at 16:10

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1

If you use the following code you may fix your problem. Give it a try.Paste this in your post.php

<?php 
if ( current_theme_supports( 'get-the-image' ) ):
    $image_full=wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'full');
    $image_thumbnail=wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'single-thumbnail');
?> 
<a href="<?php echo $image_full[0]; ?>" rel="lightbox">
<img class="alignnone wp-image-2770 size-single-thumbnail" src="<?php echo $image_thumbnail[0]; ?>" alt="2015-04-10_190211" width="636" height="460" style="opacity: 1;">
</a>
<?php
endif;
?>
1

You can get image url with wp_get_attachment_image_src and use in href. It's most often used to get the URL (src) for an image attachment: use the first element in the returned array.

So instead of your code for featured thumbnail, you should use this.

<?php

    if ( current_theme_supports( 'get-the-image' ) ) {

        $fullimage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
        echo '<a href="' . $fullimage[0] . '" rel="lightbox">' . get_the_image( array( 'meta_key' => 'Thumbnail', 'size' => 'single-thumbnail', 'link_to_post' => false, 'image_class' => 'featured', 'attachment' => false ) ) . "</a>";

    }

?>

Not the answer you're looking for? Browse other questions tagged or ask your own question.