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音乐怎么同步?
  • 微信怎么开启黑夜模式
  • 在成都怎么判断琴行靠不靠谱?
  • 进口越南椰壳炭化料清关需要哪些资料
  • 热门搜索
    江西旅游商贸职业学院 怀孕多久可以用试纸测出来 无锡 旅游 香格里拉旅游攻略 山东旅游景点大全景点排名 三孔景区 过期牛奶可以浇花吗 海南旅游路线 大连香洲旅游度假区 大溪地旅游