首页 > 新闻资讯 > 统计图片数

统计图片数

12条评论
标签:
更多

有的朋友想知道怎么统计网站里的图片,今天这段代码就可以统计媒体库中的图片总数。把第一段添加到functions.php中

function img_count(){
    $query_img_args = array(
        'post_type' => 'attachment',
        'post_mime_type' =>array(
                        'jpg|jpeg|jpe' => 'image/jpeg',
                        'gif' => 'image/gif',
                'png' => 'image/png',
                ),
        'post_status' => 'inherit',
        'posts_per_page' => -1,
        );
    $query_img = new WP_Query( $query_img_args );
    echo $query_img->post_count;
}

第二代添加到你想显示的页面中

<?
   img_count();
?>

* 版权声明:作者WordPress啦! 转载请注明出处。

#1
这个非常棒!!!!
#2
哎,没有办法啊。我都没有怎么传过图片。
#3
原来这么简单啊,不错!
#4
还有这样的功能
#5
谢谢分享啊
#6
这个功能能牛叉的
#7
这个功能我的博客应该是用不到的。
#8
不错的教程,应该学习才行咯。
#9
这个真是非常实用
#10
增加去对申请google广告也有帮助啊
#11
对我非常有用,谢谢
#12
用图片还更省资源啊。

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自动断行和分段。

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.