好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

如何获取文章的第一张图片 - WordPress

如何获取文章的第一张图片

首先在当前模板中的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的详细内容...

  阅读:64次