wordpress无插件实现文章浏览数
获取文章浏览量(pv),网上介绍了wp-views插件,安装过,没有效果。偶得一个方法。
第一步:将以下代码贴到主题的 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 View";
}
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);
}
}
第二步:在文章的内容循环代码里加上以下代码
<?php setPostViews(get_the_ID()); ?>
第三步:将以下代码放到任何需要显示文章浏览量的地方
<?php echo getPostViews(get_the_ID()); ?>
更多阅读
- 宇秀搜索引擎下拉及相关搜索推荐营销系统增加随机标签【功能添加】
- 宇秀-搜索引擎下拉推荐营销系统6.561新增异步刷法
- centos apache安装wordpress插件出现需要输入ftp帐号的问题(已解决)
- wordpress获取所在分类的上级父栏目id
- 百度竞价创意批量采集器2.0 竞价创意助手 免费下载
- Vim变身IDE:易学易用功能强大的vim配置
- drupal 7 移除自带的 css 和 javascript 及 jQuery.extend(Drupal.settings,
- windows 操作系统实现快速宽带拨号命令[批处理下载]
- nginx 下 drupal 8升级提示 update.php/selection not found
- docker 基础操作(实战一) 怎样删除容器、镜像

qq:1535604235


QQ
微信
商店
裕康网志
2017年10月8日 下午7:53
不见博主在用。
fedkey
2017年10月10日 下午10:26
好东西也未必全用啊。个人爱好简单点