无插件实现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
- INXY→美国 法国 荷兰等独服 AMD Opteron 16GB 内存美国VPS[主机]
- 搬瓦工年付 46.8 美元起补货 DC3&DC8&DC2&DC4&弗里蒙全球[VPS测评]
- 双十一 iON→2 核 CPU 4G 内存套餐 新加坡 洛杉矶机房 月付全球[VPS测评]
- 玩具-invs→3.2 元 月 512MB 内存 5GB 空间 不限流量虚拟空间(主机)
- spinservers→美国服务器 30 分钟上机 超便宜+超高配+10美国VPS[主机]
- 修罗云→45 元 月 512MB 内存 6GB 空间 1TB 流量 10虚拟空间(主机)
- 欧洲一般-SpectraIP→€2.5 月 1 核 1G 1T 流量 自全球[VPS测评]
- 云上互联→20.8 元 月 512MB 内存 35GB 空间 不限流量 虚拟空间(主机)
- [优惠]CloudCone 1810 闪购全球[VPS测评]
- ZeptoVM 1G内存 10G SSD 1T双向流量 50M国际带宽 全球[VPS测评]
- 很简单的图片不规则布局样式,纯css样式实现的图片瀑布流布局全球[VPS测评]
- 香港云服务器怎么选?云服务器性能测评对比香港VPS[主机]
- 企鹅小屋:香港VPS限时3折优惠,香港沙田CN2,原生IP,年付486.香港VPS[主机]
- 阿里行癫:如何理解当下的云计算全球[VPS测评]
- VPSPlayer,超便宜香港cn2线路小带宽VPS,2核4G内存仅30香港VPS[主机]
- 蓝米云:美国cera vps/香港cn2vps套餐,1核2G/40G/1美国VPS[主机]
- JGKVM(极光kvm),便宜香港VPS(5G防御秒解),极光互联vps香港VPS[主机]
- 咖啡主机怎么样?美国洛杉矶高防vps,cn2直连,香港沙田vps美国VPS[主机]
- wordpress 上传附件报错 “抱歉,出于安全的考虑,不支持此文件类全球[VPS测评]
- anyhk香港HKT商宽NAT VPS,1Gbps无限流量,终身8折¥3香港VPS[主机]
- 播放量破千万,点赞量破百万,你绝对想不到这三款多功能产品居然在TK上卖爆全球[VPS测评]
- 桔子数据:香港CN2大带宽云服务器28元/月_1核/1G/10M带宽/C香港VPS[主机]
- 金斗云双12活动:全场8折起,美国圣何塞CN2 GIA高防VPS20元/美国VPS[主机]
- 关键路径、资金情况、政策关键数据中心的可持续发展路径在哪里?全球[VPS测评]
- JGKVM:1核/512M/30G/600G/30Mbps/洛杉矶CN2全球[VPS测评]
- 景林网络:香港CN2vps,1核1G3M月付35元;美国高防vps,48美国VPS[主机]
- 弘速科技:香港安畅CN2+BGP线路1核2G/8M带宽秒杀款120元/年香港VPS[主机]
- 二三互联,香港cn2云服务器5折+85折双重优惠,稳定不限流量,1核1G香港VPS[主机]
- CMCUCT:2核2GB/20GB香港ntt线路vps 6TB流量/1G香港VPS[主机]
- 全球云lovps,香港CN2线路vps 新品七折月付49元香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-142819.html











