有些信息不够放在单独一个页面里, 也不好总是显示在显眼的地方(浪费空间) 所以最好就显示在每页的最底下,比如就是博客的统计信息.
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;?>条评论
是不是很简单呢?
强烈推荐
- 英国代购-畅购英伦
- TopCashBack 返现 (英国购物必备, 积少成多, 我2年来一共得了3000多英镑)
- Quidco 返现 (也是很不错的英国返现网站, 返现率高)
- 注册就送10美元, 免费使用2个月的 DigitalOcean 云主机(性价比超高, 每月只需5美元)
- 注册就送10美元, 免费使用4个月的 Vultr 云主机(性价比超高, 每月只需2.5美元)
- 注册就送10美元, 免费使用2个月的 阿里 云主机(性价比超高, 每月只需4.5美元)
- 注册就送20美元, 免费使用4个月的 Linode 云主机(性价比超高, 每月只需5美元) (折扣码: PodCastInit2022)
- PlusNet 英国光纤(超快, 超划算! 用户名 doctorlai)
- 刷了美国运通信用卡一年得到的积分 换了 485英镑
- 注册就送50英镑 – 英国最便宜最划算的电气提供商
- 能把比特币莱特币变现的银行卡! 不需要手续费就可以把虚拟货币法币兑换
微信公众号: 小赖子的英国生活和资讯 JustYYUK