logo of Shuibaco

网站统计数据

2011. / 474字 / 909阅 / 0评

之前在别人博客上曾经看到过关于自己博客的一些统计数据,赛恩找啊找,终于被我找到这篇文章:给wordpress添加一个小统计和这篇文章:wp边栏博客统计的代码(链接失效)。于是,我依葫芦画瓢把自己博客的统计数据加在了页脚,如下所示:

网站统计数据
网站统计数据

添加方法很简单:到后台打开 index.php,在里面喜欢的位置选择加入以下几个参数和代码(当然,也可以选择在 single.php 或者其他喜欢的位置添加这些数据,不过一般来说都是添加在首页),然后保存。

文章:<?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish; ?>
浏览:<?php get_totalviews(true, true, true); ?>
评论:<?php $total_comments = get_comment_count(); echo $total_comments['approved'];?>
会员:<?php $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); echo $users; ?>
链接:<?php $link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); echo $link; ?>
更新:<?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日', strtotime($last[0]->MAX_m));echo $last; ?>
页面:<?php $count_pages = wp_count_posts('page'); echo $page_posts = $count_pages->publish; ?>
草稿:<?php $count_posts = wp_count_posts(); echo $draft_posts = $count_posts->draft; ?>
分类:<?php echo $count_categories = wp_count_terms('category'); ?>
标签:<?php echo $count_tags = wp_count_terms('post_tag'); ?>
运行:<?php echo floor((time()-strtotime("2011-10-30"))/86400); ?>

前后的文字可以自己看着修改,比如要实现以上我的效果,代码为:

<?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish; ?> posts |
<?php get_totalviews(true, true, true); ?> |
<?php $total_comments = get_comment_count(); echo $total_comments['approved'];?> comments |
last updated on <?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', strtotime($last[0]->MAX_m));echo $last; ?>
1,146°
隐藏已知评论者信息
Comments
Write a Comment
点击加载Disqus