到目前为止,我添加了一个侧边栏,用于博客和单个博文。我在侧边栏中添加了最近的评论部分,相应地在博客页面中显示,但问题是它不会显示在单个帖子中。以下是显示最新评论的代码。这项工作在博客页面中,但在单个帖子中显示为空。如何在单页中显示最近的评论?
$comments = get_comments( 'number=4' );
foreach( $comments as $comment ){
$comment_title = get_the_title( $comment->comment_post_ID );
$comment_link = get_comment_link( $comment->comment_ID );
$comment_temp = get_comment( $comment->comment_ID, ARRAY_A );
$comm_content = $comment_temp['comment_content'];
$post_id = $comment->comment_post_ID;
$images_id = get_post_thumbnail_id( $post_id );
$images_url = wp_get_attachment_image_src( $images_id, 'recent-blog', true );
?>
<li class="list-group-item">
<div class="row">
<div class="col-sm-4">
<figure>
<a href="<?php echo($comment_link)?>"><img src="<?php echo $images_url[0];?>" alt="latest" class="img-responsive"></a>
</figure>
</div>
<div class="col-sm-8">
<h4><a href="<?php echo($comment_link)?>"><?php echo( $comment->comment_author );?></a></h4>
<p><?php echo comment_excerpt();?></p>
</div>
</div>
</li>
<?php } ?>
&#13;
&GT;