这列出了“我的自定义分类法模板”页面中的帖子:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
如何按评论数排序这些帖子?这列出了“我的自定义分类法模板”页面中的帖子:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
如何按评论数排序这些帖子?一位朋友帮助我提出了一个解决方案,我可以将其放在我的函数中。php文件:
add_filter( \'pre_get_posts\', \'my_pre_get_posts\' );
function my_pre_get_posts( $query ) {
if ( is_tax( \'locations\' ) && empty( $query->query_vars[\'suppress_filters\'] ) )
$query->set( \'orderby\', \'comment_count\' );
return $query;
}
WP Query自2.9以来有一个comment\\u count参数。
因此:
query_posts(array(\'orderby\' => \'comment_count\', \'posts_per_page\' => \'10\'));
if ( have_posts() ) : while ( have_posts() ) : the_post();