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

前端之家收集整理的这篇文章主要介绍了简单实现 WordPress 统计图片数量的代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

猜你在找的wordpress相关文章