事实上,我刚刚完成了一个需要在其提要中添加图像的网站的工作,因此我最终使用了以下内容:
function ba_post_image_feeds($content) {
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)){
$content = \'<div>\' . $first_img . \'</div>\' . $content;
}
return $content;
}
add_filter(\'the_excerpt_rss\', \'ba_post_image_feeds\');
add_filter(\'the_content_feed\', \'ba_post_image_feeds\');