WordPress:获取附加的图像高度和宽度 [英] WordPress: Get attached image height and width
问题描述
在 WordPress 中,我从帖子中抓取附加图像并将它们显示在无序列表中.它工作得很好,除了我现在需要以与获取 src
相同的方式获取图像 height
和 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;
}
知道我该怎么做吗?
推荐答案
您可以使用 wp_get_attachment_image_src($attachment_id)
,它应该返回一个类似 ('/path/to/img.jpg',32,64)
的数组,其中 32 是宽度,64 是高度...阅读wordpress codex,了解有关此功能用法的更多信息.
You can use wp_get_attachment_image_src($attachment_id)
, it should return an array like ('/path/to/img.jpg',32,64)
where 32 is the width and 64 is the height... Read the wordpress codex for more information on the usage of this function.
这篇关于WordPress:获取附加的图像高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!