插件实现浏览数
1.打开网站后台,找到插件,安装插件
2.搜索PostViews插件并且启用
3.在合适的位置放置:<?php if(function_exists(‘the_views’)) { the_views(); } ?>即可
代码实现浏览数
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 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);
}
}
2.然后在显示的地方用代码调用:
<?php
setPostViews(get_the_ID());
?>
想知道自己的网站文章被浏览多少次,赶紧放上浏览数代码吧。