wordpress 实现这个首页自动显示文章内容缩略图的功能。
//获取文章第一张图片,如果没有图就会显示默认的图 function catch_the_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-thumb.jpg'; } return $first_img; }
使用时,直接在循环里使用这个方法就可以了:
catch_the_image();
今天看到打架 那叫一个厉害 还好我没带我家哈奇士去 不然 哼哼。。。我还得背着它回来说多了都是泪。。。。。。。。 http://url.cn/XfB45g
有空一起交流一下