首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >add_image_size不使用the_post_thumbnail

add_image_size不使用the_post_thumbnail
EN

WordPress Development用户
提问于 2015-12-29 15:04:46
回答 1查看 7K关注 0票数 1

我的funcitons.php中的代码

代码语言:javascript
复制
function custom_thumbs() {
    add_image_size( 'cover-size', 1600, 450, true ); 
}
add_action( 'after_setup_theme', 'custom_thumbs' );

用法:

echo the_post_thumbnail($post->ID,'cover-size');

但结果是:

代码语言:javascript
复制
<img width="3648" height="2736" src="http://localhost/sonru/wp-content/uploads/2015/12/DSC04656.jpg" class="attachment-9 size-9 wp-post-image" alt="DSC04656" cover-size="" srcset="http://localhost/sonru/wp-content/uploads/2015/12/DSC04656-300x225.jpg 300w, http://localhost/sonru/wp-content/uploads/2015/12/DSC04656-600x450.jpg 600w" sizes="(max-width: 3648px) 100vw, 3648px">

我在这里错过了什么?

-编辑-

我已经在用regenerate thunbnails插件重新生成缩略图了

EN

回答 1

WordPress Development用户

发布于 2015-12-29 15:41:41

您正在使用错误的函数:

  • the_post_thumbnail()不接受post ID作为值,而是接受图像大小。
  • get_the_post_thumbnail()是您所需要的,也许是尝试使用的。第一个参数接受post ID,第二个参数接受要使用的图像大小,如在您的问题中一样。

溶液

the_post_thumbnail()交换get_the_post_thumbnail()

编辑

请注意,在添加了对缩略图的支持之后,确保添加了新的图像大小。此外,您还需要使用set_post_thumbnail_size()添加一个新的帖子缩略图大小。

票数 1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/213191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档