最佳答案 array -6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 13:08:41 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com