给wordpress博客添加统计代码

博主推荐【腾讯云】爆款2核2G云服务器首年40元

如果想在WordPress博客首页或内页显示有关wordpress站点的统计代码,如:文章数量,评论数量,博客至今运行多少天等,可以把以下代码复制博客文件中的适当位置即可。

<h3>站点统计</h3>
文章数量:<?php $count_posts = wp_count_posts();
echo $published_posts = $count_posts->publish; ?>
评论数量:<?php $total_comments = get_comment_count();
echo $total_comments[‘approved’];?>
分类数量:<?php echo $count_categories = wp_count_terms(‘category’); ?>
页面数量:<?php $count_pages = wp_count_posts(‘page’);
echo $page_posts = $count_pages->publish; ?>
链接数量:<?php $link = $wpdb->get_var(“SELECT COUNT(*) FROM $wpdb->links
WHERE link_visible = ‘Y'”); echo $link; ?>
标签数量:<?php echo $count_tags = wp_count_terms(‘post_tag’); ?>
站点成立:某年某月某日
运行天数:<?php echo floor((time()-strtotime(“20xx-x-xx”))/86400); ?>天
最后更新:<?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; ?>

注:在“运行天数”代码中的20xx-x-xx更改为博客实际的成立时间,如:2013-1-01

原创文章转载请注明:转载自 七行者博客

本文固定链接: https://www.qxzxp.com/2917.html

给wordpress博客添加统计代码:目前有3 条留言

  1. 0楼
    番茄:

    没有访问次数的统计代码哈

    2016-04-21 16:06 [回复]
  2. 0楼
    康秋华:

    不错,说得好,大家鼓掌

    2015-12-31 06:56 [回复]

发表评论

4 + 6 =

快捷键:Ctrl+Enter