WordPress怎样自动获取文章缩略图
函数代码如下:自动获取文章中第一张图片否则使用默认图片
<?php //自动截图设置
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];
if(empty($first_img)){
$first_img = bloginfo(‘template_url’). ‘/images/default.jpg’;
}
return $first_img;
}
//结束
?>
这个早就在用了,另外已经帮您点。。击。。百度。。广告,希望您也能帮我创点收入!
额,客官轻点~~~还是自然流量自然点击的好~~
哈哈哈,我就是在把以前在网上找到的方法整理下,怕忘了~~