如何按视图数升序查看帖子?
这只是供内部使用,以便我可以看到不同帖子的表现。目前,如果我在仪表板中查看帖子,我只能按日期进行筛选。有900多篇帖子,我希望能够按视图数的顺序查看它们。视图是一个字段,但我不能按它排序。
如何按视图数升序查看帖子?
这只是供内部使用,以便我可以看到不同帖子的表现。目前,如果我在仪表板中查看帖子,我只能按日期进行筛选。有900多篇帖子,我希望能够按视图数的顺序查看它们。视图是一个字段,但我不能按它排序。
使用以下代码段跟踪wordpress博客上的帖子视图。您要做的第一件事是将此代码段添加到函数中。wordpress主题的php。遵循步骤1。和步骤2。跟踪和显示每篇文章的视图数。这篇文章的作者
http://wpsnipp.com/index.php/cache/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);
}
}
// Remove issues with prefetching adding extra views
remove_action( \'wp_head\', \'adjacent_posts_rel_link_wp_head\', 10, 0);
这是我为你做的,效果很好!您必须将download\\u counter更改为您拥有的任何帖子元!
$popularpost = new WP_Query( array( \'meta_key\' => \'download_counter\', \'orderby\' => \'meta_value_num\', \'order\' => \'DESC\' ,\'paged\' => get_query_var( \'page\' ) ) );
while ( $popularpost->have_posts() ) : $popularpost->the_post();
global $post;
/// loop here
endwhile;
使用下载计数器的post元数据,然后使用此查询获取所需的数据
$loop = new WP_Query( array(
\'meta_key\' => \'download_counter\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ACS\'
) );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
.
.
.
endwhile;
我正在自定义页面模板,在从自定义字段获取页面id时遇到问题。自定义字段的值包含要调用其内容的页面ID。对于普通页面,我会这样做:<?php query_posts(\'page_id=155\'); global $more; $more = 1; ?> 但是如何获取自定义字段的值作为查询的页面ID?提前感谢托蒂