php - 如何通过在 wordpress 中获取帖子图像来更改宽度和高度?

标签 php html css wordpress

我正在循环获取帖子图片,每张图片都将以新的宽度和高度显示。我在如何在 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 ] )

来自 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]; ?>">

关于php - 如何通过在 wordpress 中获取帖子图像来更改宽度和高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15703044/

相关文章:

php - 对于功能不起作用

php - 总是使用 MySQL 的项目应该使用 PDO 吗?

php - 获取由选择选项填充的文本值

javascript - 如何使用 FileSystem API 的 window.requestFileSystem?

javascript - AngularJS ng-switch 在 <p> 标签上抛出错误

css - IE7/8 margin-bottom 折叠问题

php - 用额外的字段保存 HABTM?

javascript - 范围过滤器仅在第一个 Controller 中工作

安卓透明白底黑边

android - Ionic 3 - 如何实现 viewpager?