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

简单实现 WordPress 统计图片数量的代码,第1张

概述有的朋友想知道怎么统计网站里的图片,今天这段代码就可以统计媒体库中的图片总数。把第一段添加到functions.php中 function img_count(){ $query_img_args = array( 'post_type' => 'attachment', 'post_mime_type' =>array( 'jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/g…

有的朋友想知道怎么统计网站里的图片,今天这段代码就可以统计媒体库中的图片总数。把第一段添加到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 统计图片数量的代码全部内容,希望文章能够帮你解决简单实现 WordPress 统计图片数量的代码所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zz/1004077.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存