colindunn colindunn - 24 days ago 8
PHP Question

Wordpress: Get attached image height and width

In WordPress, I am grabbing attached images from a post and displaying them in an unordered list. It works great, except I need to now get the image

height
and
width
, in the same way that I got the
src
. This is my code:

PHP

$post_thumbnail_id = get_post_thumbnail_id( $iPostID );
foreach( $arrKeys as $key) {
if( $key == $post_thumbnail_id )
continue;
$sImageUrl = wp_get_attachment_url($key);
$sImgString = '<li><img src="' . $sImageUrl . '" alt="Thumbnail Image" /></li>';
echo $sImgString;
}


Any idea how I can do this?

Answer

You can use wp_get_attachment_image_src(), it should return an array like ('/path/to/img.jpg',32,64) where 32 is the width and 64 is the height...

Comments