wordpress个性化站点统计
来自 http://www.zzhck.com/491.html
效果如下:
实现这个功能需要修改主题的footer.php和css文件
在footer.php中,你想让出现的位置(左侧,中间,右侧)添加如下代码
<!--站点统计开始-->
<span class="btn-primary web-sta"><i class="icon-map-marker icon-white icon12"></i> 站内统计</span>
<div class="statistics">
<h3>站内统计</h3>
<ul>
<li>建站日期:2014-07-31</li>
<li>运行天数:<?php echo floor((time()-strtotime("2014-07-31"))/86400); ?> 天</li>
<li>分类总数:<?php echo $count_categories = wp_count_terms('category'); ?> 个</li>
<li>日志总数:<?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?> 篇</li>
<li>标签数量:<?php echo $count_tags = wp_count_terms('post_tag'); ?> 个</li>
<li>评论总数:<?php echo $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments");?> 条</li>
<li>链接数量:<?php $link = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); echo $link; ?> 个</li>
<li>最后更新:<?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; ?></li>
</ul>
</div>
<script type="text/javascript">
$(".footer-inner span.web-sta").hover(function(){
$(".footer-inner .statistics").slideDown("slow");
},function(){
$(".footer-inner .statistics").slideUp("slow");
});
</script>
<!--站点统计结束-->
然后修改主题的css文件,增加如下代码
/* 底部站点统计 */
span.web-sta{display:inline-block;height:22px;line-height:22px;padding:0 5px;margin:auto 0px auto 5px;cursor:pointer}
.footer .statistics{max-width:360px;border:1px solid #ddd;border-left:0;position:absolute;top:-156px;right:-1px;font-size:12px;background-color:#444;cursor:pointer;display:none}
.footer .statistics h3{border:0;border-bottom:1px dashed #ff8540;font-size:16px;height:25px;line-height:25px;padding:0px 20px 8px;text-align:left}
.footer .statistics ul{padding:5px 8px;position:relative}
.footer .statistics ul li{min-width:150px;display:inline-block;margin-left:10px;margin-bottom:5px}
.footer .statistics ul li:hover{background-color:#eee}
最后再次感谢王海达老师,他教会了我很多,自己动手,用心学习,前端代码没有秘密可言
标签:WordPress