Wordpress - 如何列出某些类别中评论最多的帖子

时间:2011-04-21 16:03:18

标签: wordpress

我希望在我的WP网站上添加十大类型列表。

我目前有以下内容,但我需要能够从多个类别ID中获取帖子,有人知道我会怎么做吗?

提前感谢您的帮助。

<div>
<?php
$args=array(
  'cat' => 75, // this is category ID
  'orderby' => 'comment_count',
  'order' => 'DESC',
  'post_type' => 'post',
  'post_status' => 'publish',
  'posts_per_page' => 10, // how much post you want to display
  'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { ?>
    <ul>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
    <?php  endwhile; ?>
    </ul>
<?php }

wp_reset_query(); ?>
</div>

1 个答案:

答案 0 :(得分:2)

我已经在我的开发网站上测试了您的代码,它可以满足您的需求;但是,如果WP_DEBUG设置为true,则会收到错误,指示参数caller_get_posts在3.1中已弃用。根据您的PHP设置和服务器配置,这可能会导致您的问题。我建议做出以下改变:

<div>
<?php
$args=array(
  'cat' => 75, // this is category ID
  'orderby' => 'comment_count',
  'order' => 'DESC',
  'post_type' => 'post',
  'post_status' => 'publish',
  'posts_per_page' => 10, // how much post you want to display
  'ignore_sticky_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { ?>
    <ul>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
    <?php  endwhile; ?>
    </ul>
<?php }

wp_reset_query(); ?>
</div>

唯一的变化是将ignore_sticky_posts替换为caller_get_posts

相关问题