您好,登錄后才能下訂單哦!
小編給大家分享一下按評論數(shù)量顯示前100名評論者的方法,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
如想看看自己博客上哪位博友的留言評論最多及最后的評論時間,下面一段代碼會幫你實現(xiàn)這個功能。
可以將下面代碼添加到當(dāng)前主題functions.php中:
function top_comment_authors($amount = 100) { global $wpdb; $prepared_statement = $wpdb->prepare( 'SELECT COUNT(comment_author) AS comments_count, comment_author, comment_author_url, MAX( comment_date ) as last_commented_date FROM '.$wpdb->comments.' WHERE comment_author != "" AND comment_type = "" AND comment_approved = 1 GROUP BY comment_author ORDER BY comments_count DESC, comment_author ASC LIMIT %d', $amount); $results = $wpdb->get_results($prepared_statement); $output = '<ul class="top-comments">'; foreach($results as $result) { $output .= '<li class="top-comment-author"><strong> <a href="'.$result->comment_author_url.'" target="_blank" rel="external nofollow">'.$result->comment_author.'</a></strong> 共'.$result->comments_count.' 條評論,最后評論 '.human_time_diff(strtotime($result->last_commented_date)).'前</li>'; } $output .= '</ul>'; echo $output; }
調(diào)用代碼:
<?php top_comment_authors(100); ?>
將代碼添加到WordPress主題模板適當(dāng)位置即可,其中的數(shù)字100可以控制顯示數(shù)量。
以上是按評論數(shù)量顯示前100名評論者的方法的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。