WordPress,程序自帶評論,留言數,文章數等統計代碼總結

公元2011年10月30日沒人鳥我喲打醬油看熱鬧的有:2,544 views

WordPress,程序自帶評論,留言數,文章數等統計代碼總結

經常看到一些博客在側欄或者底欄等地方有一些關於博客的留言,文章,用戶,等一些統計數據,其實這些數據可以通過一些很簡單的代碼實現,下面就把這些代碼總結出來,喜歡的朋友可以根據需要添加!

下面直接放出代碼,大家可以根據需要添加,直接將代碼插入到需要的位置即可!

博客用戶統計

1
2
<?php $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); 
echo $users; ?></li>

博客日誌統計

1
2
<?php $count_posts = wp_count_posts(); echo $published_posts = 
$count_posts->publish;?></li>

博客評論統計

1
2
3
4
5
6
7
8
9
10
11
<span title="訪客/管理員:<?php $comment_guest = $wpdb->get_var("SELECT COUNT(*) 
FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type != 
'trackback' AND comment_type != 'pingback' AND user_id = 0"); 
echo $comment_guest; ?>/<?php $comment_author = $wpdb->get_var("SELECT COUNT(*) 
FROM $wpdb->comments WHERE comment_approved = '1' 
AND comment_type != 'trackback' AND comment_type != 'pingback' AND user_id > 0"); 
echo $comment_author; ?>">評論總數:<?php
$comment = $wpdb->get_var("SELECT COUNT(*) 
FROM $wpdb->comments WHERE comment_approved = '1' 
AND comment_type != 'trackback' AND comment_type != 'pingback'");
echo $comment;?></span></li>

博客標簽統計

1
<?php echo $count_tags = wp_count_terms('post_tag'); ?></li>

博客分類統計

1
<?php echo $count_categories = wp_count_terms('category'); ?></li>

博客頁面統計

1
2
<?php $count_pages = wp_count_posts('page'); echo $page_posts = 
$count_pages->publish; ?></li>

博客鏈接統計

1
2
<?php $link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE 
link_visible = 'Y'"); echo $link; ?></li>

博客草稿統計

1
<?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts->draft; ?>

博客最後更新時間

1
2
3
4
5
<?php $last = $wpdb->get_results("SELECT MAX(post_modified) AS MAX_m 
FROM $wpdb->posts WHERE (post_type = 'post' OR post_type = 'page') 
AND (post_status = 'publish' OR post_status = 'private')");
$last = date('Y-n-j g:ia', strtotime($last[0]->MAX_m));
echo $last; ?>

OK!暫時就先這些吧,以後隨時可能會再添加,希望能夠幫到有需要的朋友,收工! 休息一下,馬上回來!