效果预览:
获取图片数量代码:
代码: 全选
/*****************
* 获取图片数量
* @since 2016.07.01
**/
function hui_post_imgNum($content){
$output =
preg_match_all("/\<img.*?src\=\"(.*?)\"[^>]*>/i", $content,$matches);
$cnt = count( $matches[1] );
return $cnt;
}
使用之前,请先将上面的代码添加到当前主题下的 functions.php文件里。
调用代码:
代码: 全选
<?php echo ''.hui_post_imgNum($this->content).'' ; ?>
【对php不太熟,如果代码有什么不妥的地方,欢迎批评指正 \\*^o^*// 可爱ㄋㄟ~ 】