简体   繁体   English

如何从Wordpress中获取帖子图像来更改宽度和高度?

[英]how can i change the width and height from fetching post images in wordpress?

I'm fetching the post images in a loop and each of which would display with new width and height. 我正在以循环方式获取帖子图像,每个图像都将以新的宽度和高度显示。 I'm having problem in how should i define width and height in img tag. 我在应如何在img标签中定义宽度和高度时遇到问题。

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

array getimagesize ( string $filename [, array &$imageinfo ] ) 数组getimagesize(字符串$ filename [,数组&$ imageinfo])

from http://php.net/manual/en/function.getimagesize.php 来自http://php.net/manual/en/function.getimagesize.php

Also, from http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src 另外,来自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]; ?>">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM