我有一个简单的页面,我想显示尚未评论的帖子列表。我该怎么做?我认为这是我可以添加到 query_posts 的一些参数?谢谢。

最佳答案

不幸的是 query_posts 不允许您将查询限制为 comment_count=0 。你可以这样做:

query_posts( 'orderby=comment_count&order=ASC' );

但这不仅显示零评论的帖子,它只会首先显示零评论的帖子。

更复杂(但更好)的解决方案是使用自定义查询,该查询专门将查询限制为具有 0 条评论的帖子,但这意味着您必须创建自己的循环结构(至少 so far as I can tell )
global $wpdb;
$query = "
  SELECT *
  FROM {$wpdb->prefix}posts
  WHERE
  {$wpdb->prefix}posts.post_type = 'post'
  AND {$wpdb->prefix}posts.post_status = 'publish'
  AND {$wpdb->prefix}posts.comment_count = 0
  ORDER BY {$wpdb->prefix}posts.post_date
  DESC;
";

$pageposts = $wpdb->get_results($query, OBJECT);

 <?php if ($pageposts): ?>
 <?php global $post; ?>
 <?php foreach ($pageposts as $post): ?>
 <?php setup_postdata($post); ?>

 <div class="post" id="post-<?php the_ID(); ?>">
 <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    <?php the_title(); ?></a></h2>
    <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
    <div class="entry">
       <?php the_content('Read the rest of this entry »'); ?>
    </div>
    <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>
    <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
 </div>
 <?php endforeach; ?>
 <?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php include (TEMPLATEPATH . "/searchform.php"); ?>
 <?php endif; ?>

这似乎在您的知识范围内实现吗?

10-08 00:14