搜尋
首頁CMS教程&#&按如何按評論數量顯示前100名評論者

下面由WordPress建站教學專欄給大家介紹按評論數量顯示前100名評論者的方法,希望對需要的朋友有所幫助!

如何按評論數量顯示前100名評論者

如想看看自己部落格上哪位博友的留言留言最多及最後的留言時間,以下一段程式碼會幫你實現這個功能。

可以將下面程式碼新增至目前主題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 = &#39;<ul class="top-comments">&#39;;
    foreach($results as $result) {
        $output .= &#39;<li class="top-comment-author"><strong> <a href="&#39;.$result->comment_author_url.&#39;" target="_blank" rel="external nofollow">&#39;.$result->comment_author.&#39;</a></strong> 共&#39;.$result->comments_count.&#39; 条评论,最后评论 &#39;.human_time_diff(strtotime($result->last_commented_date)).&#39;前</li>&#39;;
    }
    $output .= &#39;</ul>&#39;;
    echo $output;
}

呼叫程式碼:

<?php top_comment_authors(100); ?>

將程式碼新增至WordPress主題模板適當位置即可,其中的數字100可以控制顯示數量。

以上是如何按評論數量顯示前100名評論者的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:zmingcx。如有侵權,請聯絡admin@php.cn刪除
WordPress與其他流行的CMS平台相比如何?WordPress與其他流行的CMS平台相比如何?May 02, 2025 am 12:18 AM

WordPressExcccelineaseeandAdaptability,MakeitItiDealForBeginnersandsMallToMedium-SizedBusinesses.1)siseofuse:wordpressisuser-Frylyly.2)安全:drupalleadswithstrongsecurityfeatures.3)性能:performance:performance formation:phast offersefersefersefersefersefersefersefersefersexcellentperformanceedueTonode.sscore.jssor.jjsy.jjsy.4)4)

您可以使用WordPress構建會員網站嗎?您可以使用WordPress構建會員網站嗎?May 01, 2025 am 12:08 AM

是的,您可以使用Plypluginslikememberpress,PayMembersubScriptions,OrwooCommerceForuserManagemention,ContentAccesControl,andPaymentMenthandling.2)

WordPress是否需要編碼知識作為CMS?WordPress是否需要編碼知識作為CMS?Apr 30, 2025 am 12:03 AM

你不需要編程知識就能使用WordPress,但掌握編程可以提升體驗。 1)使用CSS和HTML可以調整主題樣式。 2)PHP知識能編輯主題文件,添加功能。 3)自定義插件和元標籤可優化SEO。 4)注意備份和使用子主題以防更新問題。

使用WordPress時的安全考慮是什麼?使用WordPress時的安全考慮是什麼?Apr 29, 2025 am 12:01 AM

TosecureaWordPresssite,followthesesteps:1)RegularlyupdateWordPresscore,themes,andpluginstopatchvulnerabilities.2)Usestrong,uniquepasswordsandenabletwo-factorauthentication.3)OptformanagedWordPresshostingorsecuresharedhostingwithawebapplicationfirewal

WordPress與其他網站構建者相比如何?WordPress與其他網站構建者相比如何?Apr 28, 2025 am 12:04 AM

WordPressExcelSoverotherWeberSiteBuilderSduetoItsflexible,可伸縮性,andopen-sourcenature.1)它'saversatilecmswithExtEnsextEnsexenSiveCustomizedOptionsVIATHEMESANDPLUGINS.2)它的alllearbutoffersbutoffersbutoffersbutoffersbutefersbuterbutfulcontrololoncemastered.3)

5個WordPress插件,供開發人員在2025年使用5個WordPress插件,供開發人員在2025年使用Apr 27, 2025 am 08:25 AM

2025年網站開發的七個必備WordPress插件 在2025年建立頂級WordPress網站需要速度,響應能力和可擴展性。 實現這種有效的實現通常取決於戰略插件的選擇。 這篇文章Highlig

您將使用WordPress做什麼?您將使用WordPress做什麼?Apr 27, 2025 am 12:14 AM

WordPresscanbeusedforvariouspurposesbeyondblogging.1)E-commerce:WithWooCommerce,itcanbecomeafullonlinestore.2)Membershipsites:PluginslikeMemberPressenableexclusivecontentareas.3)Portfoliosites:ThemeslikeAstraallowstunninglayouts.Ensuretomanageplugins

WordPress適合創建投資組合網站嗎?WordPress適合創建投資組合網站嗎?Apr 26, 2025 am 12:05 AM

是的,wordpressisisexcellentforcortingaportfoliowebsite.1)itoffersnumeroversnumeroverportfolio-spificthemeslike'astra'astra'astra'astra'astra'astra'astra'astra'astra'elementor'Enelementor'enableIntiviveSiveSign,Thoughtemanycanslowthesite.3)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

SecLists

SecLists

SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中