无插件实现WordPress文章尾部加入作者介绍模块
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

蜗牛在浏览网友博客的时候经常看到文章尾部都有作者的介绍,感觉比较帅气,如果是多作者网站还可以顺带介绍到不同文章不同作者的信息,这样也可以给其他作者一些较大幅度的露脸机会。当然,要实现这样的功能有很多办法,比如直接利用插件、直接调用后台个人信息模块参数,如果是单作者博客,可以直接在内容页模板底部直接加入HTML模块就可以实现。
在这篇文章中,蜗牛直接采用无插件模块方式,自动调用网站作者信息实现的。
1、调用脚本
//作者信息
function wpb_author_info_box( $content ) {
global $post;
// Detect if it is a single post with a post author
if ( is_single() && isset( $post->post_author ) ) {
// Get author\’s display name
$display_name = get_the_author_meta( \’display_name\’, $post->post_author );
// If display name is not available then use nickname as display name
if ( empty( $display_name ) )
$display_name = get_the_author_meta( \’nickname\’, $post->post_author );
// Get author\’s biographical information or description
$user_description = get_the_author_meta( \’user_description\’, $post->post_author );
// Get author\’s website URL
$user_website = get_the_author_meta(\’url\’, $post->post_author);
// Get link to the author archive page
$user_posts = get_author_posts_url( get_the_author_meta( \’ID\’ , $post->post_author));
if ( ! empty( $display_name ) )
$author_details = \'<p class=\”author_name\”>About \’ . $display_name . \'</p>\’;
if ( ! empty( $user_description ) )
// Author avatar and bio
$author_details .= \'<p class=\”author_details\”>\’ . get_avatar( get_the_author_meta(\’user_email\’) , 90 ) . nl2br( $user_description ). \'</p>\’;
$author_details .= \'<p class=\”author_links\”><a h=\”\’. $user_posts .\’\”>View all posts by \’ . $display_name . \'</a>\’;
// Check if author has a website in their profile
if ( ! empty( $user_website ) ) {
// Display author website link
$author_details .= \’ | <a h=\”\’ . $user_website .\’\” target=\”_blank\” rel=\”nofollow\”>Website</a></p>\’;
} else {
// if there is no author website then just close the paragraph
$author_details .= \'</p>\’;
}
// Pass all this info to post content
$content = $content . \'<footer class=\”author_bio_section\” >\’ . $author_details . \'</footer>\’;
}
return $content;
}
// Add our function to the post content filter
add_action( \’the_content\’, \’wpb_author_info_box\’ );
// Allow HTML in author bio section
remove_filter(\’pre_user_description\’, \’wp_filter_kses\’);
将代码直接添加到当前主题functions.php文件中。
2、添加CSS样式
.author_bio_section{
background: none repeat scroll 0 0 #F5F5F5;
padding: 15px;
border: 1px solid #ccc;
}
.author_name{
font-size:16px;
font-weight: bold;
}
.author_details img {
border: 1px solid #D8D8D8;
border-radius: 50%;
float: left;
margin: 0 10px 10px 0;
}
添加CSS到当前主题中,这样我们刷新页面看看是否调用出来。
3、修正个人信息
我们可以看到已经可以调用个人信息,然后我们去后台个人信息里补全个人信息即可。
当然,如果我们需要美化功能,可以调整添加进Functions.php脚本的布局,以及CSS样式,也可以手工加一点文件,这个主要还是看我们各自的需要。
猜你可能想看的VPS
- 疯狂猜成语 图猜成语七个脚印上写着轻舟已过万重山是什么成语?全球[VPS测评]
- 大流量 VPS $6 月 512M 内存 30G SSD 5T 流量 1日本VPS[主机]
- Sharktech→$69 月-E3 1230v2 16GB 2TB 1全球[VPS测评]
- 增配通知 Vultr→不加价为 VPS 套餐增加 30%-220%的 S虚拟空间(主机)
- NAT 6yun→1 核 256MB 内存 5G 硬盘 2T 流量 10全球[VPS测评]
- 搬瓦工 VPS 一键安装 Windows 系统教程WINDOWS
- 云创网络洛杉矶安畅 cn2 gia 速度及综合性能测评,200M 带宽+全球[VPS测评]
- 华为云双十一→云服务器 196 元 年起+优惠礼包(代金券)全球[VPS测评]
- 教程 宝塔面板搭建妹子图片站 自带爬虫采集 94imm 程序全球[VPS测评]
- 疯狂猜成语 图猜成语一个老人旁边一个红色的叉一个绿色的问号是什么成语?全球[VPS测评]
- Rabbithosts→4400 元 月 2 核 4GB 内存 20GB虚拟空间(主机)
- 免费 VPS 伏羲云→美国 CN2 线路低 19 元 月 日本 香港直连日本VPS[主机]
- js 比较两个时间大小函数全球[VPS测评]
- 阳帝云 1核1G10M大宽带香港BGP月付14元香港VPS[主机]
- HostXen 双十一充值送 云主机充300元送50元 充600送150全球[VPS测评]
- DMIT洛杉矶新上sPro方案自带Cloudflare防御/CN2GIA全球[VPS测评]
- DeHost → 1.8$ 月 土耳其 2C2G30G硬盘 DDOS保护全球[VPS测评]
- Alpha bd → 18$ 月 孟加拉VPS Linux 2核2G30全球[VPS测评]
- Hostsailor-复活节半价1.5$ 月 512M内存25G硬盘 5美国VPS[主机]
- 极客主机,优惠8折充值返25%,香港CN2VPS,日本软银VPS,新加坡日本VPS[主机]
- 什么是Bootstrap?全球[VPS测评]
- 跨境电商平台首选香港服务器香港VPS[主机]
- 云计算竞争日趋白热化云计算行业市场前景分析全球[VPS测评]
- HostHatch:1核/2GB/20GB空间/KVM/香港/洛杉矶/纽虚拟空间(主机)
- HostKVM香港云地VPS,2核4G内存折后$8.4/月,30M大带宽香港VPS[主机]
- 碳氧云,香港vps路由调整为沙田cn2,特价款6核6G仅80元/月香港VPS[主机]
- 好朋友51WORLD启动“地球克隆计划5”,我要去元宇宙参加了全球[VPS测评]
- Ceraus:香港CN2云服务器,香港GIA VPS去程移动回程路线,月香港VPS[主机]
- 一万网络双蛋狂欢活动:2核2G5M云服务器仅377.46元/年全球[VPS测评]
- 极光KVM:1核/1G/40G/100Mbps/美国GIA,年付199元美国VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-39818.html











