一、把下面这段代码加在模板文件夹内的functions.php文件内
//统计文章浏览次数
function getPostViews($postID){
$count_key = 'views';
$count = get_post_meta($postID, $count_key, true);
if($count=='' || !$count){
return "0";
}
return $count;
}
function setPostViews($postID){
$count_key = 'views';
$count = get_post_meta($postID, $count_key, true);
if($count=='' || !$count) {
$count = 1;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, $count);
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
二、调用、显示文章浏览次数:
把下面这段代码加在想显示文章浏览次数的位置
2、显示列表页文章浏览次数:
在列表页显示查看次数,在列表页需要显示查看次数的位置单独添加下面的代码
(\wp-content\plugins\elementor-pro\modules\posts\skins\skin-base.php)
 浏览-
//如下
render_author();
}
if ( in_array( 'date', $settings ) ) {
$this->render_date_by_type();
}
if ( in_array( 'time', $settings ) ) {
$this->render_time();
}
if ( in_array( 'comments', $settings ) ) {
$this->render_comments();
}
if ( in_array( 'modified', $settings ) ) {
$this->render_date_by_type( 'modified' );
}
?>
 浏览-
修改浏览数量→后台文章列表→点击数字修改
