WordPress:列出没有评论的帖子 [英] WordPress: List posts with no comments

查看:112
本文介绍了WordPress:列出没有评论的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

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

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

但这不只是显示没有评论的帖子,



更多参与(但更好)的解决方案是使用自定义查询, 0评论,但这意味着您必须创建自己的循环结构(至少我可以告诉

  global $ wpdb; 
$ query =
SELECT *
FROM {$ wpdb-> prefix} posts
WHERE
{$ wpdb-> prefix} posts.post_type =' post
和{$ wpdb-> prefix} posts.post_status ='publish'
和{$ 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 =postid =post-<?php the_ID();?>>
< h2>< a href =<?php the_permalink()?> rel =bookmarktitle =永久链接到<?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('读此条目的其余部分»'); ?>
< / div>
< p class =postmetadata>发布在<?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>找不到< / h2>
< p class =center>抱歉,您正在寻找不在这里的东西。< / p>
<?php include(TEMPLATEPATH。/searchform.php); ?>
<?php endif; ?>


I have simple page that I want to display a list of posts that haven't been commented on yet. How would I do this? I presume it's some parameters I can add to the query_posts? Thanks.

解决方案

Unfortunately query_posts does not allow you to limit the query to comment_count=0. You can do this:

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

But that does not only display posts with zero comments, it just displays those with zero comments first.

The more involved (but better) solution is to use a custom query that specifically limits the query to posts with 0 comments, but that means you would have to create your own loop structure (at least 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; ?>

Does that seem within your knowledge to implement?

这篇关于WordPress:列出没有评论的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆