有的朋友想知道怎么統計網站里的圖片,今天這段代碼就可以統計媒體庫中的圖片總數。把第一段添加到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