Display authors list with permalink and sort by comments count

时间:2015-07-08 15:56:29

标签: php comments

I would like to create a Page where display a list of the authors sort by comments count. I found only this on the web:

in 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;
}

Then I called back the function in my Template Page:

<?php top_comment_authors(); ?>

But the author link ($result->comment_author_url) doesn't work correctly. The link connects me to the same page where I am currently. Any advice?

Thank you in advance

1 个答案:

答案 0 :(得分:0)

通常在wordpress中,可以使用

显示评论作者链接
<?php echo get_comment_author_link( $comment_ID ); ?>