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

发布于 2024-11-02 10:53:53 字数 894 浏览 1 评论 0原文

我希望在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各空 2024-11-09 10:53:53

我已经在我的开发网站上测试了您的代码,它可以满足您的要求;但是,当 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

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:

<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>

With the only change being substituting ignore_sticky_posts for caller_get_posts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文