我正在构建一个模板,wordpress主要用作图像CMS,我从每篇文章的内容部分提取第一幅图像。
<img src="<?php echo grab_image() ?>" />
function grab_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];
if(empty($first_img)){
$first_img = "";
}
return $first_img;
}
我的问题是,我如何从上传的图片库中抓取第一张图片,而不是从post\\u内容中抓取?因此,添加图像的过程将是上载然后退出(不插入帖子)。我不知道你叫它什么,也不知道该找什么。。附件?媒体库?内容区域将严格用于文本以及任何额外的元框。