在 WordPress 中,我从帖子中抓取附加图像并将它们显示在无序列表中。它效果很好,除了我现在需要获取图像height
and width
,就像我得到的一样src
。这是我的代码:
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) http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src,它应该返回一个像这样的数组('/path/to/img.jpg',32,64)
其中 32 是宽度,64 是高度...阅读WordPress 法典 http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src有关使用此功能的更多信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)