Where are you trying to use this (template file)? What theme are you using? Can you show us the code that isn’t working.
I’m trying to use this in the loop (index). I’m using gridly.
I was trying codex first example :
<?php
$attachment_id = 8; // attachment ID
$image_attributes = wp_get_attachment_image_src( $attachment_id ); // returns an array
?>
<img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>">
Without success since I can’t get the attchment_id… So it doesn’t return anything 🙁
What is it exacly you want to do and on what page or template file? Get the first attachment of a post?
I want to get the dimension of the posts thumbnails displayed on index page.
So I plan to use get_attachment_image_src function. In order to do so, I need to know the thumbnail id (“attchment_id” in the code).
Ah, it’s a post thumbnail.
Try it with get_post_thumbnail_id():
http://codex.wordpress.org/Function_Reference/get_post_thumbnail_id
// inside the loop
$id = get_post_thumbnail_id( $post->ID );
$image = wp_get_attachment_image_src( $id, 'summary-image' );
$width = $image[1];
$height = $image[2];
That’s exactly what I needed… Thanks a lot !
You’re welcome. I’m glad you’ve got it resolved 🙂