在做图片墙的时候要在缩略图下显示文章中一共有多少张图片。也许你在制作主题的过程中也会有这方面的需要,可以在当前主题目录下的functions.php文件中加入以下代码来实现
1 2 3 4 5 6 7 8 9 10 11 |
//获取文章图片数量 function pic_total() { global $post; $post_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/\<img.+?src="(.+?)".*?\/>/is ', $post->post_content, $matches, PREG_SET_ORDER); $post_img_src = $matches [0][1]; $cnt = count($matches); return $cnt; } |
添加之后在主题模板中调用 这个函数就行了
1 |
<?php echo pic_total(); ?> 张图片 |
本站图片墙就使用了这个函数,蛮不错的!
这个对于图片站来说很有用