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>
I am looking to add a top ten type list to my WP website.
I currently have the following but I need to be able to make it get posts from multiple category IDs, does anybody know how I would go about doing this?
Thanks in advance for your help.
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经在我的开发网站上测试了您的代码,它可以满足您的要求;但是,当 WP_DEBUG 设置为 true 时,我收到一条错误,表明参数
caller_get_posts
在 3.1 中已弃用。根据您的 PHP 设置和服务器配置,这可能会给您带来问题。我建议进行以下更改:唯一的更改是用
ignore_sticky_posts
替换caller_get_posts
。I've tested your code on a dev site of mine and it does what you are wanting; however, with WP_DEBUG set to true, I get an error indicating that the parameter
caller_get_posts
is deprecated in 3.1. Depending on your PHP setup and server config, this could cause problems for you. I would suggest making the following change:With the only change being substituting
ignore_sticky_posts
forcaller_get_posts
.