将查询更改为:
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
收件人:
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 .= "<li><a href=".$result->comment_author_url.">".$result->comment_author."</a> (".$result->comments_count.")</li>";
收件人:
$output .= "<li><a href=".get_author_posts_url($result->user_id).">".$result->comment_author."</a> (".$result->comments_count.")</li>";
修改查询将授予您访问所有字段的权限,其中一个字段(user\\u id)将用于获取作者的页面
get_author_posts_url();
Update
我建议您在SQL字符串上使用双引号,在HTML上使用单引号。在您的代码中,您试图将$输出与任何内容连接起来。
因此,您的查询可能如下所示:
"
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><a href="\'.get_author_posts_url($result->user_id).\'">\'.$result->comment_author.\'</a> (\'.$result->comments_count.\')</li>\';
}
$output .= \'</ul>\';
希望有帮助!