wordpress取得文章中第一张图片url地址的函数
因为要改版一个功能希望取文章中所有图片中的第一张图片作为缩略图了,下面我就来给各位同学分享一个我整理了函数,希望对大家有帮助,wordpress取得文章中第一张图片url,代码如下:
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]; // no image found display default image instead if ( empty empty ( $first_img )){ $first_img = "/images/default.jpg" ; } www.phpfensi.com return $first_img ; }查看更多关于wordpress取得文章中第一张图片url地址的函数 - W的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did8839