Wordpress:检查帖子是否允许评论


Wordpress: Check posts have comments allowed

我有一个页面显示来自某个类别的某些帖子,在本例中为类别 33(教程),它当前输出标题、帖子摘录和永久链接到此类别中的帖子:

<?php $top_query = new WP_Query('cat=33'); ?>
<?php while($top_query->have_posts()) : $top_query->the_post(); ?>

如何指定返回的帖子应仅是启用了评论的帖子?我试过把它包装在:

<?php if(comments_open()) : ?> 

需要在循环中使用的悬停:(

提前致谢

试试这个

<?php if( have_posts() ): ?>
        <?php while( have_posts() ): the_post();?>
                   <?php if(comments_open()){ ?> 
                    <div class="news-row">
                    <?php if (has_post_thumbnail( $post->ID ) ): ?>
                        <div class="newsimagebox">
                          <?php //$feat_image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID),'thumbnail');
                              $images = the_post_thumbnail();?>
                           <?php echo $images;?>
                        </div>
                    <?php endif; ?>
                    <div class="news-content">
                    <h5><?php the_title(); ?></h5>              
                    <p><?php the_excerpt();?></p>
                    <div class="readmore"><a href="<?php echo get_permalink(); ?>" title="Read More">Read More</a></div>
                </div>
            </div>
                   <?php } ?>
        <?php endwhile;?>
<?php endif; //wp_reset_query(); ?>

谢谢