WordPress 中获取最新被评论的文章列表
要在WordPress中获取最新被评论的文章列表,您可以使用WP_Query或get_comments

方法一:使用WP_Query
$args = array(
    'post_type' => 'post',  // 文章类型
    'orderby' => 'comment_count',  // 根据评论数排序
    'order' => 'DESC',  // 降序排序
    'posts_per_page' => 10  // 显示的文章数量
);
$query = new WP_Query($args);
if ($query>have_posts()) :
    while ($query>have_posts()) : $query>the_post();
        // 在这里显示文章标题、链接或其他内容
        the_title();
        the_permalink();
    endwhile;
    wp_reset_postdata();
else :
    echo '没有找到符合条件的文章。';
endif;方法二:使用get_comments
$comments_args = array(
    'number' => 10,  // 获取的评论数量
    'status' => 'approve',  // 仅获取已批准的评论
    'orderby' => 'comment_date',  // 根据评论日期排序
    'order' => 'DESC'  // 降序排序
);
$comments = get_comments($comments_args);
foreach ($comments as $comment) {
    $comment_post = get_post($comment>comment_post_ID);
    // 在这里显示文章标题、链接或其他内容
    echo '<a href="' . get_permalink($comment_post) . '">' . get_the_title($comment_post) . '</a><br>';
}这两种方法都可以用来获取最新被评论的文章列表,您可以根据需要选择其中一种。在这两种方法中,您可以根据实际需求调整参数,例如文章数量、排序方式等。
 
                        仍然有问题? 我们要如何帮助您? 
                    
                 
             
             
             
             
        

 
                        