2013-03-29 48 views
0

我正在循環提取後期圖像,每個圖像都會顯示新的寬度和高度。我在如何定義img標籤中的寬度和高度時遇到問題。我如何改變從wordpress中獲取帖子圖片的寬度和高度?

<?php 
$image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 
     'single-post-thumbnail'); 
?> 
<img src="<?= $image[0]; ?>" alt="" width="" height="" /> 
+1

除非你可以將其設置爲變量然後我建議不要打擾它。 –

+0

看一看:http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src –

回答

0

陣列和getimagesize(字符串$文件名[,陣列& $的imageinfo])

http://php.net/manual/en/function.getimagesize.php

另外,從http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

<?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]; ?>"> 
相關問題