我正在构建一个自定义 Wordpress 主题,并在任何单个帖子上显示所有评论,而不仅仅是该帖子的评论。显然,我希望只显示对该帖子的评论。
<?php
//Get only the approved comments
$args = array(
'status' => 'approve'
);
// The comment Query
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query( $args );
// Comment Loop
if ( $comments ) {
echo '<ol class="post-comments">';
foreach ( $comments as $comment ) {
?>
<li class="post-comment">
<div class="comment-avatar">
<div><?php echo get_avatar( $comment, 32 ); ?></div>
</div>
<div class="comment-content">
<div class="comment-meta">
<p class="comment-author"><?php echo $comment->comment_author; ?></p>
<p class="comment-date"> <?php echo $comment->comment_date; ?></p>
</div>
<p class="comment-text"><?php echo $comment->comment_content; ?></p>
</div>
</li>
<?php
}
echo '</ol>';
} else {
echo 'No comments found.';
}
?>
我本质上是在使用这段代码,我直接从 wordpress.org 获得的
<?php
$args = array(
// args here
);
// The Query
$comments_query = new WP_Comment_Query( $args );
$comments = $comments_query->comments;
// Comment Loop
if ( $comments ) {
foreach ( $comments as $comment ) {
echo $comment->comment_content;
}
} else {
echo 'No comments found.';
}
?>