如何在 wordpress 主题页脚显示一些统计信息?


有些信息不够放在单独一个页面里, 也不好总是显示在显眼的地方(浪费空间) 所以最好就显示在每页的最底下,比如就是博客的统计信息.

wordpress 每个主题都应该会有一个叫 footer.php 的文件,可以找到页底显示信息那里,插入以下PHP代码,就可以显示博客运行天数, 文章和页面总数,还有评论数.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
global $wpdb;// https://helloacm.com
$query = "select count(1) from `wp_posts` where `post_status`='publish' and `post_type`='post'";
$cnt_posts = $wpdb->get_var($query);
$query = "select count(1) from `wp_posts` where `post_status`='publish' and `post_type`='page'";
$cnt_pages = $wpdb->get_var($query);
$query = "select count(1) from `wp_comments` where `comment_approved`=1";
$cnt_comments = $wpdb->get_var($query);
$start = strtotime("2011-07-03 00:00:00");  // 需要把这个日期换成你第一篇博客的日期.
$today = strtotime(date("Y-m-d h:i:s"));
$days = round(abs($today - $start) / 3600 / 24);
?>
 
博客运行了 <?php echo $days;?>, 一共有<?php echo $cnt_posts;?>篇博文 和 <?php echo $cnt_pages;?>篇页面, 一共有<?php echo $cnt_comments;?>条评论
<?php
global $wpdb;// https://helloacm.com
$query = "select count(1) from `wp_posts` where `post_status`='publish' and `post_type`='post'";
$cnt_posts = $wpdb->get_var($query);
$query = "select count(1) from `wp_posts` where `post_status`='publish' and `post_type`='page'";
$cnt_pages = $wpdb->get_var($query);
$query = "select count(1) from `wp_comments` where `comment_approved`=1";
$cnt_comments = $wpdb->get_var($query);
$start = strtotime("2011-07-03 00:00:00");  // 需要把这个日期换成你第一篇博客的日期.
$today = strtotime(date("Y-m-d h:i:s"));
$days = round(abs($today - $start) / 3600 / 24);
?>

博客运行了 <?php echo $days;?> 天, 一共有<?php echo $cnt_posts;?>篇博文 和 <?php echo $cnt_pages;?>篇页面, 一共有<?php echo $cnt_comments;?>条评论

是不是很简单呢?

GD Star Rating
loading...
本文一共 160 个汉字, 你数一下对不对.
如何在 wordpress 主题页脚显示一些统计信息?. (AMP 移动加速版本)
上一篇: 在英国做家教挣些零花钱
下一篇: 有想法的QQ骗子

扫描二维码,分享本文到微信朋友圈
09c328d71cfffa5e3c4ac7bf2ab660df 如何在 wordpress 主题页脚显示一些统计信息? 互联网 折腾 网站信息与统计

9 条评论

  1. 里念
  2. ASOUT

评论