Top Commenters: exclude admin

时间:2011-11-20 作者:japanworm

我在函数中使用以下代码。php显示“我的主题”中的顶级评论者:

function top_comment_authors($amount = 5){

    global $wpdb;

    $results = $wpdb->get_results(\'
        SELECT
            COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url
        FROM
            \'.$wpdb->comments.\'
        WHERE
            comment_author_email != "" AND comment_type = "" AND comment_approved = 1
        GROUP BY
            comment_author_email
        ORDER BY
            comments_count DESC, comment_author ASC
        LIMIT \'.$amount

    );

    $output = "<ul>";
    foreach($results as $result){
    $output .= "<li>".get_avatar($result->comment_author_email, 30).\' <p>\'.(($result->comment_author_url) ? "<a href=\'".$result->comment_author_url."\'>" : "").$result->comment_author.(($result->comment_author_url) ? "</a>" : "")." (".$result->comments_count.")</p></li>";
    }
    $output .= "</ul>";

    echo $output;
}
很好,但我想exclude 我自己,又名admin/著者这有可能吗?如果是这样,我会怎么做?我必须以何种方式修改上述代码?

提前非常感谢!:)

2 个回复
最合适的回答,由SO网友:fuxia 整理而成

扩展WHERE子句:

WHERE
    comment_author_email != "" 
    AND comment_author_email != "YOUR_MAIL_ADDRESS" 
    AND comment_type = "" 
    AND comment_approved = 1 
)
如果要排除多个电子邮件地址,请使用NOT IN 运算符和逗号分隔的字符串列表:

AND comment_author_email NOT IN ( "[email protected]", "[email protected]" )

SO网友:JMau

评论\\作者\\电子邮件没问题,但就我而言,我更喜欢使用用户id:

AND user_id!="1" 
它应该能完成任务!

结束