小兽向大家介绍了wordpress统计当前文章图片数量+附文字数量统计等相关知识,希望对您有所帮助
统计图片的数量

有些图片比较多wordpress网站会比较需要获取文章图片总数,函数放到functions中即可。调用的地方加入<?php echo pic_total(); ?>
function pic_total() {
global $post;
$post_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/\<img.+?src="(.+?)".*?\/>/is ', $post->post_content, $matches, PREG_SET_ORDER);
$post_img_src = $matches [0][1];
$cnt = count($matches);
return $cnt;
}
统计文章字数的数量
//字数统计
function count_words ($text) {
global $post;
if ( '' == $text ) {
$text = $post->post_content;
if (mb_strlen($output, 'UTF-8') < mb_strlen($text, 'UTF-8')) $output .= '本文共' . mb_strlen(preg_replace('/\s/','',html_entity_decode(strip_tags($post->post_content))),'UTF-8') . '个字';
return $output;
}
}
调用方式<?php echo count_words ($text); ?>

