WP_Comment_Query 中的评论对象为空
Comment object empty in WP_Comment_Query
这是我的 PHP 代码:
<?php
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query( array( 'number' => 5 ) );
if ($comments)
{
foreach ( $comments as $comment ) {
?>
<div class="comment" id="comment-<?php $comment->comment_ID ?>">
<div class="avatar">
<?php get_avatar( $comment->comment_author_email, 48 ); ?>
</div>
<div class="text>
<a class="author" href="<?php get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; ?>">
<?php get_comment_author( $comment->comment_ID ) ?>
</a>
<?php strip_tags( substr( apply_filters( 'get_comment_text', $comment->comment_content ), 0, 80 ) ) . '...'; ?></p>
</div>
</div>
<?php
}
} else {
echo 'none.';
}
?>
这是一条评论的结果 HTML:
<div class="comment" id="comment-">
<div class="avatar">
</div>
<div class="text>
<a class=" author"="" href="">
<p></p>
</div>
</div>
我有评论所以 'none.' 没有打印出来。但是,如您所见,评论对象是空的。我missing/what怎么回事?
我是 运行 WP 4.2.2.
谢谢,
约书亚
知道了,有些愚蠢,但即使我调用了方法,我也没有 echo
结果。
这是我的 PHP 代码:
<?php
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query( array( 'number' => 5 ) );
if ($comments)
{
foreach ( $comments as $comment ) {
?>
<div class="comment" id="comment-<?php $comment->comment_ID ?>">
<div class="avatar">
<?php get_avatar( $comment->comment_author_email, 48 ); ?>
</div>
<div class="text>
<a class="author" href="<?php get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; ?>">
<?php get_comment_author( $comment->comment_ID ) ?>
</a>
<?php strip_tags( substr( apply_filters( 'get_comment_text', $comment->comment_content ), 0, 80 ) ) . '...'; ?></p>
</div>
</div>
<?php
}
} else {
echo 'none.';
}
?>
这是一条评论的结果 HTML:
<div class="comment" id="comment-">
<div class="avatar">
</div>
<div class="text>
<a class=" author"="" href="">
<p></p>
</div>
</div>
我有评论所以 'none.' 没有打印出来。但是,如您所见,评论对象是空的。我missing/what怎么回事?
我是 运行 WP 4.2.2.
谢谢, 约书亚
知道了,有些愚蠢,但即使我调用了方法,我也没有 echo
结果。