加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

简单实现 WordPress 统计图片数量的代码

发布时间:2020-12-14 14:18:14 所属栏目:wordpress 来源:网络整理
导读:有的朋友想知道怎么统计网站里的图片,今天这段代码就可以统计媒体库中的图片总数。把第一段添加到functions.php中 function img_count(){ $query_img_args = array( 'post_type' = 'attachment', 'post_mime_type' =array( 'jpg|jpeg|jpe' = 'image/jpeg',

有的朋友想知道怎么统计网站里的图片,今天这段代码就可以统计媒体库中的图片总数。把第一段添加到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.la

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读