我可以看到,在我的上传文件夹中,我上传到帖子中的所有图片都有4种不同的大小。
我没有为帖子设置的特色图片,但我想让缩略图大小显示在我的头版。
我尝试过将the_post_thumbnail();放在循环中,但是没有显示任何内容。
我是不是遗漏了什么?有没有另一种方法来抓取一个缩略图大小的图片,已经放置在文章中?
目前,我使用一个捕获图像函数来抓取文章中的第一个图像,并在首页上显示它的代码,这能被编辑以获得缩略图吗?
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
//$first_img = substr($first_img, 0, -4);
if(empty($first_img)){ //Defines a default image
$first_img = bloginfo('template_directory');
$first_img .= "/images/default.png";
}
return $first_img;
}谢谢
发布于 2015-05-09 12:38:12
the_post_thumbnail显示文章中的特色图片,所以如果您没有设置任何图片,它就不会显示任何内容。
https://stackoverflow.com/questions/30127818
复制相似问题