我经常使用这个功能来提取后的图像:WP/PHP函数来提取图像不起作用
function first_post_image($content) {
$first_img = '';
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
$first_img = $matches [1] [0];
return $first_img;
}
然后我展示用下面的代码
<?php $postimage = first_post_image(get_the_content()); ?> // catch the image
<img src="<?php echo $postimage; ?>" /> //view the image
图像
现在我尝试在我的最后一个模板(wp)中使用此功能,但图像未显示。我可以看到标签img和src属性,但它是空的。
有人可以帮助我吗?谢谢