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()); ?>
更多阅读
- 网站编辑如何写受搜索引擎喜欢的seo原创文章
- 2017年百度新算法: “闪电算法”上线,3秒打不开的网页将被无情打压
- mariadb异常 mysqld: Out of memory Centos 创建swap分区解决
- drupal 7 移除自带的 css 和 javascript 及 jQuery.extend(Drupal.settings,
- 网址链接有效性批量检测工具2.1
- 鸿蒙是基于安卓或Linux系统开发的吗?一个搞技术的用大家都能懂的方式来谈一下
- 百度竞价信息采集与排名查询助手3.0.4发布
- 宇秀下拉 2021-4-12下拉更新案例
- cargo 命令行备忘 rust开发必备命令行
- 宇秀下拉 2021-3-21下拉更新案例

qq:1535604235


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