如何在WordPress主题开发中添加作者信息框?

玖比肆 WordPress 42

作者信息框可以展示作者的个人信息,本文将为您讲解如何在WordPress主题开发中添加作者信息框。

回复

共1条回复 我来回复
  • 玖比肆的头像
    玖比肆 评论

    在WordPress主题开发中添加作者信息框,可以通过以下步骤实现:

    1. 添加自定义用户字段
    打开functions.php文件,添加以下代码:

    function add_author_fields( $contactmethods ) {
    $contactmethods['phone_number'] = 'Phone Number';
    $contactmethods['facebook'] = 'Facebook URL';
    $contactmethods['twitter'] = 'Twitter URL';
    $contactmethods['github'] = 'GitHub URL';

    return $contactmethods;
    }
    add_filter( 'user_contactmethods', 'add_author_fields', 10, 1 );

    此代码将添加电话号码、Facebook、Twitter和GitHub等自定义字段。

    2. 创建作者信息框
    在主题的单个文章页面中,添加一个包含作者信息的HTML元素。例如,可以使用以下代码:

    About the Author



    这将显示包含作者头像、名称、描述、电话号码、Facebook、Twitter和GitHub链接的作者信息框。

    3. 样式作者信息框
    将以下CSS代码添加到主题的style.css文件中以美化作者信息框:

    .author-box {
    margin: 50px auto;
    padding: 20px;
    background-color: #ffffff;
    border: 1px solid #e5e5e5;
    border-radius: 5px;
    box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.1);
    text-align: center;
    }

    .author-box h2 {
    font-size: 24px;
    margin-bottom: 20px;
    }

    .author-box .avatar {
    display: inline-block;
    margin-bottom: 20px;
    }

    .author-box .avatar img {
    border-radius: 50%;
    }

    .author-box .author-info {
    text-align: left;
    }

    .author-box .author-info h3 {
    font-size: 18px;
    margin-bottom: 10px;
    }

    .author-box .author-info p {
    font-size: 16px;
    margin-bottom: 20px;
    }

    .author-box .author-info ul {
    list-style: none;
    margin: 0;
    padding: 0;
    }

    .author-box .author-info ul li {
    margin-bottom: 5px;
    }

    .author-box .author-info ul li span {
    font-weight: bold;
    }

    .author-box .author-info ul li a {
    text-decoration: none;
    color: #0066cc;
    }

    这样,您就可以在WordPress主题开发中添加作者信息框了。

    2023年 4月 26日 下午3:42 0条评论
微信客服
分享本页
返回顶部
玖比肆(9Bi4)专注于帮助企业实现数字化转型,提供全方位的网站建设、网络运营、网络推广、网络营销和SEO优化等一系列数字化营销服务。