[英]Listing comments by author else not working
I have a code that listing comments by author. 我有一个列出作者评论的代码。 I use it in author.php.
我在author.php中使用它。 It list comments perfectly but if the author has no comments it shows other authors comment links.
它完美地列出了评论,但是如果作者没有评论,它将显示其他作者的评论链接。
the code 编码
<?php
$args = array(
'user_id' => get_the_author_meta('ID'),
'number' => 5, // how many comments to retrieve
'status' => 'approve'
);
$comments = get_comments( $args );
if ( $comments )
{
foreach ( $comments as $c )
{
$output.= '<li">';
$output.= '<a href="'.get_comment_link( $c->comment_ID ).'">';
$output.= get_the_title($c->comment_post_ID);
$output.= "</a></li>\n";
}
echo $output;
} else { echo "There is no comment yet.";}
?>
i want to see here if author has no comment: else { echo "There is no comment yet.";} 我想在这里查看作者是否还没有评论: 否则{echo“还没有评论。”;}
Your code looks fine. 您的代码看起来不错。 Are you sure the get_the_author_meta('ID') function returns the correct value?
您确定get_the_author_meta('ID')函数返回正确的值吗?
I fixed it by changing: 'user_id' => get_the_author_meta('ID'),
我通过更改来解决它:
'user_id' => get_the_author_meta('ID'),
i changed it as: 'author_email' => $curauth->user_email,
我将其更改为:
'author_email' => $curauth->user_email,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.