首页 > 解决方案 > 如何使特色图像/缩略图具有响应性?

问题描述

我正在寻找一些代码,以使我的图像缩略图在我调整浏览器大小时以它们调整大小的方式响应,如果这有意义的话。所以我找到了这段代码,它有点工作:

if ( has_post_thumbnail() ) {
    $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),’thumbnail’ );
    echo '<img width="100%" src="' . $image_src[0] . '">';
}

唯一的问题是它给了我这个错误:

警告:使用未定义的常量 'thumbnail' - 假定为 ''thumbnail''

(这将在 PHP 的未来版本中引发错误)

所以我想知道是否有一种新的方法可以做到这一点。

谢谢!

标签: phpwordpress

解决方案


It looks like you have copied this code from somewhere else.

So in $image_src image size thumbnail have copied Single Quotes.

Remove that Quotes and try the default editor's Single or Double quote and try again.


推荐阅读