wordpress列表页调用浏览器,wordpress显示文章浏览量!
1、把下面這段代碼加在想顯示文章瀏覽次數(shù)的位置(例如模板內(nèi)的content.php)
<?php setPostViews(get_the_ID()); echo getPostViews(get_the_ID()); ?>
2、如果需要在列表頁顯示查看次數(shù),那么建議在列表頁需要顯示查看次數(shù)的位置單獨添加下面的代碼
<?php echo getPostViews(get_the_ID()); ?>
把下面這段代碼加在模板文件夾內(nèi)的functions.php文件內(nèi)
//統(tǒng)計文章瀏覽次數(shù)
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 查看";
}
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);
}
}
文章來源:https://www.technicalanalysis.cn/
---------------------?
作者:a1079540945?
來源:CSDN?
原文:https://blog.csdn.net/a1079540945/article/details/84548302?
版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請附上博文鏈接!
總結(jié)
以上是生活随笔為你收集整理的wordpress列表页调用浏览器,wordpress显示文章浏览量!的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 飞机大战项目(源代码(直接用),有效果图
- 下一篇: python飞机大战游戏素材_pytho