用干净的代码了解WordPress文章点击量的教程
站长使用WordPress搭建网站后,想知道有多少人点击了他的文章。几天后,他将分享一个关于如何用纯代码实现 WordPress 文章点击计数的教程。您可以将以下代码粘贴到主题的functions.php 文件中。
函数 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');
返回“0个视图”;
}
'返回$count。浏览量' ;
}
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
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 post 循环中:
最后,将以下代码复制到主题模板中要显示点击的位置:
版权声明
本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。