以前都是用WP 2.3 statistics这个插件来显示本站统计的,都说插件影响速度,但用起来还是挺方便的,二者不可兼得吧,今天没事,想想这点东西用代码搞定就可以了。 如果是做CMS模板我觉得这些还是很有用的,以前是玩cms的,后来玩bbs,现在玩WordPress了,但还是想在首页上显示这些,至少自己可以看 到,呵呵,下面是调用代码,做个记录:

  1. 用户总数:
  2. 1
    
    <?php $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); echo $users; ?> 位</li>
  3. 日志总数:
  4. 1
    
    <?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?> 篇</li>
  5. 评论总数:
  6. 1
    2
    3
    
    <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>
  7. 标签总数:
  8. 1
    
    <?php echo $count_tags = wp_count_terms('post_tag'); ?> 个</li>
  9. 分类总数:
  10. 1
    
    <?php echo $count_categories = wp_count_terms('category'); ?> 个</li>
  11. 页面总数:
  12. 1
    
    <?php $count_pages = wp_count_posts('page'); echo $page_posts = $count_pages->publish; ?> 个</li>
  13. 链接总数:
  14. 1
    
    <?php $link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); echo $link; ?> 个</li>
  15. 成立时间:
  16. 1
    
    <span title="已经在线 &lt;?php echo floor((time()-strtotime("> 天"&gt;成立时间:2009.7.5</span>
  17. 最后更新:
  18. 1
    2
    3
    
    <?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; ?>
  19. 草稿数目:
  20. 1
    
    <?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts->draft; ?>

OK,停用WP 2.3 statistics,演示看首页的“本站统计”,嘿嘿

原创文章,转载请注明: 转载自老姜的博客

本文链接地址: 又干掉个插件,WordPress 统计代码

无觅相关文章插件,快速提升流量

|2|left|yes