自己制作主题的话,就会需要这些小技巧了,现成的主题一般都自己集成。
//文章点击数 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 View"; } return $count.' Views'; } 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); } }
调用方法:粘帖下面代码到主题 single.php 文件 loop 循环中:
<?php setPostViews(get_the_ID()); ?>
在需要显示的地方调用:
<?php echo getPostViews(get_the_ID()); ?>
代码弊端:刷新一次阅读数就+1,统计出来的不是最真实的。
你可能对这些文章感兴趣:
- WordPress插件推荐:xiu主题开启ajax和全站无刷新音乐的办法
- WordPress插件推荐:Facebox download
- WordPress升级到WordPress4.9的办法
- WordPress快速建站第四讲:建站中空间购买解析绑定
- 知更鸟主题图片暗箱和侧边Tab菜单失效解决办法
- WordPress复制文字自动添加版权信息
- 为WordPress自定义文章类型增加Dashicons图标
- 真是蛋疼。。。
- WordPress调用指定标签下文章来制作专题页面
- php正则匹配不以特定字符串结尾的写法
- 360浏览器如何设置不显示网页图片
- xhtml+css基础第2课-列布局
- 修复xiu主题首页cms布局错位
- WordPress后台管理友情链接
如有疑问,请前往问答中心反馈!
反馈