2011-04-21 62 views
0

我期待添加一个十大类型列表到我的WP网站。WordPress的 - 如何在特定类别中列出大多数评论文章

我目前有以下内容,但我需要能够从多个类别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> 

回答

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> 

拥有国内唯一的变化是为caller_get_postsignore_sticky_posts

相关问题