2

**this is code exemple I need a gallery of images, small photos down, clicking shows an image above. So far I can not open large image. **

<li><a data-image-id="'.$photo_id.'" href="'. get_permalink($photo_id).'"> <img data-image-id="'.$photo_id.'" class="thumbnail" src="'.get_the_post_thumbnail('small_thumbnail').'"></a></li>

1 Answer 1

4

There no WordPress function wp_get_attachment_src when you want to get answer you should clear your questions and also descriptive

I am giving you explanation of you question. you what is difference wp_get_attachment_url / wp_get_attachment_src / get_post_thumbnail_id?

wp_get_attachment_url($id)

Returns a full URI for an attachment file or false on failure. Here id is attachment post id

Example

echo wp_get_attachment_url( $id ); 
echo wp_get_attachment_url( 12 );
$example_url = wp_get_attachment_url( get_post_thumbnail_id() );
echo '<div style="background-image:url('.$example_url.');"></div>';

wp_get_attachment_image_src()

return array value of image attribute

Example

wp_get_attachment_image_src( int $attachment_id, string|array $size = 'thumbnail', bool $icon = false )

$image_attributes = wp_get_attachment_image_src( $attachment_id = 8 );
if ( $image_attributes ) : ?>
    <img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>" />
<?php endif; ?>

get_post_thumbnail_id() return featured image id

Example:

get_post_thumbnail_id($post_id)
$post_thumbnail_id = get_post_thumbnail_id( $post_id );

Now Solution of your problem

I guess $photo_id is your post id

<li><a data-image-id="'.$photo_id.'" href="'. get_permalink($photo_id).'">
<img data-image-id="'.$photo_id.'" class="thumbnail" src="'.get_the_post_thumbnail( $photo_id, 'thumbnail', array( 'class' => 'alignleft' ) );.'"></a>
</li>

for more information follow the codex:

get_post_thumbnail_id()

wp_get_attachment_image_src()

wp_get_attachment_url()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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