如何在WordPress主题开发中添加作者信息框?
作者信息框可以展示作者的个人信息,本文将为您讲解如何在WordPress主题开发中添加作者信息框。
-
玖比肆 评论在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元素。例如,可以使用以下代码:这将显示包含作者头像、名称、描述、电话号码、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
