搜索
首页CMS教程WordPress如何在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:ghandoffersefersefersefersefersefersefersefersexcellentperformanceeduetonodeutonode.jsorscor.jssor.jjsy.jjsy.jjsy.4)4)

您可以使用WordPress构建会员网站吗?您可以使用WordPress构建会员网站吗?May 01, 2025 am 12:08 AM

Yes,youcanuseWordPresstobuildamembershipsite.Here'show:1)UsepluginslikeMemberPress,PaidMemberSubscriptions,orWooCommerceforusermanagement,contentaccesscontrol,andpaymenthandling.2)Ensurecontentprotectionwithupdatedpluginsandadditionalsecuritymeasures

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

WordPressExcelSoverotherWeberteBuilderSduetoItsflexible,可伸缩性,andopen-sourcenature.1)它'saversatilecmswithExtEnsextEnsiveCustomizedOptionsVIATHEMESANDPLUGINS.2)它的alllearbutoffersbutoffersbutoffersbutoffersbutofferspopelyContrololonCemastered.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

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。