wordpress中怎么实现网站统计

 时间:2024-11-20 08:58:32

1、首先在所使用主题文件目录中找到functions.php文件,在最底位置插入下面代码:/* 实现浏览统计功能 */function getPostViews($postID){ $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); return " 0 "; } return $count;}function setPostViews($postID) { $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); }else{ $count++; update_post_meta($postID, $count_key, $count); }}

2、功能代码添加好后,我们开始进行统计,在要计算的网页中添加如下代码:<?php setPostViews(get_the_ID()); ?>

3、统计代码添加好后,接着便是进行调用统计次数,我们可以在任何地方进行添加(一般在footer.php、index.php文件等)。<?php echo getPostViews(get_the_ID()); ?> 次浏览

  • 红警OL瓜分金币活动怎么集齐赠送红包庆典字
  • 使用itunes音乐怎么同步?
  • 微信怎么开启黑夜模式
  • 在成都怎么判断琴行靠不靠谱?
  • 进口越南椰壳炭化料清关需要哪些资料
  • 热门搜索
    浙江工商职业技术学院怎么样 上汽大通g10怎么样 碎片整理在哪里 皮包脏了怎么清洗 网络延迟怎么解决 出名太快了怎么办 白血球低怎么办 淘宝红包怎么设置 陕西旅游局 无线wifi路由器