Php 使用永久链接和按注释计数排序显示作者列表

Php 使用永久链接和按注释计数排序显示作者列表,php,comments,Php,Comments,我想创建一个页面,其中显示按评论计数排序的作者列表。 我在网上只找到了这个: 在functions.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_au

我想创建一个页面,其中显示按评论计数排序的作者列表。 我在网上只找到了这个:

在functions.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><a href='".$result->comment_author_url."'>".$result->comment_author."</a></li>";
}
$output .= "</ul>";
echo $output;
}
function top\u comment\u作者($amount=5){
全球$wpdb;
$results=$wpdb->get_results('
选择
将(评论作者电子邮件)计数为评论计数、评论作者电子邮件、评论作者、评论作者url
从“$wpdb->comments”
其中,comment\u author\u email!=“和comment\u type=”“,comment\u approved=1
按评论分组\u作者\u电子邮件
按注释排序\u计数说明,注释\u作者ASC
限额‘$金额
);
$output=“
    ”; foreach($results作为$result){ $output.=“
  • ”; } $output.=“
”; echo$输出; }
然后我在我的模板页面中调用了函数:

<?php top_comment_authors(); ?>

但是作者链接($result->comment\u author\u url)不能正常工作。该链接将我连接到当前所在的同一页面。 有什么建议吗


提前感谢

通常在wordpress中,可以使用

<?php echo get_comment_author_link( $comment_ID ); ?>