搜尋
首頁CMS教程&#&按如何在WordPress 文章未尾自動新增一個作者資訊框

下面由WordPress教學欄位介紹在WordPress 文章未尾自動加入作者資訊框的方法,希望對需要的朋友有幫助!

如何在WordPress 文章未尾自動新增一個作者資訊框

如果想在WordPress#文章的結尾,加入文章作者的相關信息,下面一段程式碼可以方便在文章中新增一個作者的資訊框。

將程式碼加入目前主題functions.php:

function wp_author_info_box( $content ) {
    global $post;
    // 检测文章与文章作者
    if ( is_single() && isset( $post->post_author ) ) {
        // 获取作者名称
        $display_name = get_the_author_meta( 'display_name', $post->post_author );
        // 如果没有名称,使用昵称
        if ( empty( $display_name ) )
        $display_name = get_the_author_meta( 'nickname', $post->post_author );
        // 作者的个人信息
        $user_description = get_the_author_meta( 'user_description', $post->post_author );
        // 获取作者的网站
        $user_website = get_the_author_meta('url', $post->post_author);
        // 作者存档页面链接
        $user_posts = get_author_posts_url( get_the_author_meta( 'ID' , $post->post_author));
        if ( ! empty( $display_name ) )
        $author_details = &#39;<div class="author-name">关于 &#39; . $display_name . &#39;</div>&#39;;
        if ( ! empty( $user_description ) )
        // 作者头像
        $author_details .= &#39;<div class="author-details">&#39; . get_avatar( get_the_author_meta(&#39;user_email&#39;) , 90 ) . nl2br( $user_description ). &#39;</div>&#39;;
        $author_details .= &#39;<div class="author-links"><a href="&#39;. $user_posts .&#39;">查看 &#39; . $display_name . &#39; 所有文章</a>&#39;;
        // 检查作者在个人资料中是否填写了网站
        if ( ! empty( $user_website ) ) {
        // 显示作者的网站链接
        $author_details .= &#39; | <a href="&#39; . $user_website .&#39;" target="_blank" rel="nofollow">网站</a></div>&#39;;
        } else {
            // 如果作者没有填写网站则不显示网站链接
            $author_details .= &#39;</div>&#39;;
        }
        // 在文章后面添加作者信息
        $content = $content . &#39;<footer class="author-bio-section" >&#39; . $author_details . &#39;</footer>&#39;;
    }
    return $content;
}
// 添加过滤器
add_action( &#39;the_content&#39;, &#39;wp_author_info_box&#39; );
// 允许HTML
remove_filter(&#39;pre_user_description&#39;, &#39;wp_filter_kses&#39;);
再将配套的CSS添加到主题样式文件style.css中:
.author-bio-section {
    background: #fff;
    float: left;
    width: 100%;
    margin: 10px 0;
    padding: 15px;
    border: 1px dashed #ccc;
}
.author-name {
    font-size: 15px;
    font-weight: bold;
    margin: 0 0 5px 0;
}
.author-details img {
    float: left;
    width: 48px;
    height: auto;
    margin: 5px 15px 0 0;
}

以上是如何在WordPress 文章未尾自動新增一個作者資訊框的詳細內容。更多資訊請關注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

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

熱工具

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器