我想知道如何才能获得浏览量最大的10个页面?我知道如何使用post,但不知道如何使用page。。。
谢谢你的帮助。
我想知道如何才能获得浏览量最大的10个页面?我知道如何使用post,但不知道如何使用page。。。
谢谢你的帮助。
如果要查询页面,必须选择post_type=page
- 当然
另一个“问题”是Commo count并不能准确地表示帖子/页面视图。如果您真的想要页面浏览量,而不是评论数,请尝试下面的功能-我从这里得到:http://wpsnipp.com/index.php/functions-php/track-post-views-without-a-plugin-using-post-meta/.
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);
}
}
这样,您就必须查询新的元键post_views_count
. 就这样-祝你好运!我正在编写一个插件,该插件具有显示用户信息/数据的前端短代码。如果用户未登录,我需要重定向到前端登录页面/表单。这里的最佳做法是什么?我的插件创建我使用的页面,并向这些页面添加短代码。所以,如果有办法“保护”这些页面,我很想知道。