• 工资「喂饱肚子」,副业「养活灵魂」!

  • 本站由于前段时间遭受到大量临时和国外邮箱注册,所以对可注册的邮箱类型进行了限制!

  • 感谢大家访问本站,希望本站的内容可以帮助到大家!

  • 计算机图形学与计算几何经典必备书单整理,下载链接可参考:https://www.stubbornhuang.com/1256/

  • 如果觉得本站的内容有帮助,可以考虑打赏博主哦!

  • 在本站开通年度VIP,无限制下载本站资源和阅读本站文章

  • 本站会放置Google广告用于维持域名以及网站服务器费用。

  • 欢迎大家交换友链,可在https://www.stubbornhuang.com/申请友情链接进行友链交换申请!

  • 问题反馈可发送邮件到stubbornhuang@qq.com

WordPress – 在每一个文章内容末尾都加一个作者信息展示框

WordPress 发布于2020-12-03 阅读 3,832次 0次评论 0次点赞 本文共1503个字,阅读需要4分钟。

类似于本文内容最后的个人作者信息展示框,我们可以通过以下的步骤进行添加。

1 思路

在wordpress网站展示文章内容时添加一个函数钩子wp_author_info_box,在钩子函数中对文章内容进行修改,在文章末尾加入html代码从而完成个人作者信息的添加。

2 修改步骤

2.1 修改主题function.php

在当前主题的function.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 = '<div class="author-name">关于本站站长 ' . $display_name . '</div>';
        if ( ! empty( $user_description ) )
        // 作者头像
        $author_details .= '<div class="author-details">' . get_avatar( get_the_author_meta('user_email') , 90 ) . nl2br( $user_description ). '</div>';
        // 在文章后面添加作者信息
        $content = $content . '<footer class="author-bio-section" >' . $author_details . '</footer>';
    }
    return $content;
}
// 添加过滤器
add_action( 'the_content', 'wp_author_info_box' );
// 允许HTML
remove_filter('pre_user_description', 'wp_filter_kses');

2.2 修改主题css样式文件

在主题的css样式文件style.css文件中加入信息框的样式代码:

.author-bio-section {
    background: #fff;
    float: left;
    width: 100%;
    margin: 10px 0;
    padding: 15px;
    border: 1px dashed #7B68EE;
}
.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;
}

学过html、css的大概都看的懂吧。

欢迎扫码关注我的微信公众号,及时获取文章更新

微信公众号二维码

本文作者:StubbornHuang

版权声明:本文为站长原创文章,如果转载请注明原文链接!

原文标题:WordPress – 在每一个文章内容末尾都加一个作者信息展示框

原文链接:https://www.stubbornhuang.com/1005/

发布于:2020年12月03日 22:47:55

修改于:2023年06月26日 22:03:39

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

文章末尾
上一篇
资源分享 - 非均匀有理B样条(第二版),The NURBS Book, Second Edition 中文版PDF下载
计算几何与计算机图形学资源
下一篇
资源分享 - PHP与MySQL程序设计(第3版) 中文PDF下载
PHP资源
当前分类随机文章推荐

发表评论

您必须 [ 登录 ] 才能发表留言!

关注我们的公众号

微信公众号