如何获取文章的第一张图片
首先在当前模板中的function.php中写入:
function catch_that_image() { global $post , $posts ; $first_img = '' ; ob_start(); ob_end_clean(); $output = preg_match_all( '//i' , $post ->post_content, $matches ); $first_img = $matches [1] [0]; if ( empty empty ( $first_img )){ //Defines a default image $first_img = "/images/default.jpg" ; } return $first_img ; }然后在需要调用的地方写上.
查看更多关于如何获取文章的第一张图片 - WordPress的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did8749