【问题标题】:Listing comments by author else not working列出作者其他人的评论不起作用
【发布时间】:2018-03-24 11:22:47
【问题描述】:

我有一个按作者列出 cmets 的代码。我在 author.php 中使用它。它完美地列出了 cmets,但如果作者没有 cmets,它会显示其他作者的评论链接。

代码

<?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.";}
?>

如果作者没有评论,我想在这里查看:else { echo "There is no comment yet.";}

【问题讨论】:

    标签: wordpress comments author codex


    【解决方案1】:

    您的代码看起来不错。您确定 get_the_author_meta('ID') 函数返回正确的值吗?

    【讨论】:

    • 我认为是。如果没有,它将无法正常工作。如果用户没有评论,我只会有错误。
    【解决方案2】:

    我通过更改修复了它: 'user_id' =&gt; get_the_author_meta('ID'),

    我改成了: 'author_email' =&gt; $curauth-&gt;user_email,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-10
      • 2015-12-02
      • 2017-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 2016-01-09
      相关资源
      最近更新 更多