下面由WordPress建站教程欄目給大家介紹按評論數(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?=?'
- ‘; ????foreach($results?as?$result)?{ ????????$output?.=?‘
- ?comment_author_url.'”?target=”_blank”?rel=”external?nofollow”>’.$result->comment_author.’?共’.$result->comments_count.’?條評論,最后評論?‘.human_time_diff(strtotime($result->last_commented_date)).’前
‘; ????} ????$output?.=?‘
‘; ????echo?$output; }
調(diào)用代碼:
<?php top_comment_authors(100); ?>
將代碼添加到wordpress建站教程主題模板適當(dāng)位置即可,其中的數(shù)字100可以控制顯示數(shù)量。
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
THE END