无插件实现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
- HostYun 老品牌升级,圣何塞双程 GIA VPS 限时九折,100全球[VPS测评]
- Hostodo 便宜美国 NVMe 硬盘 VPS,高 IO 读写,1G 美国VPS[主机]
- CMIVPS→$7.5 月 KVM-1GB 10GB 500GB(50M香港VPS[主机]
- 福利 腾讯云→免费领取 100 元无门槛代金券 同时还有 500 减 2全球[VPS测评]
- 腾讯云老用户年终专享回馈→com 域名 8 元 年 1 核 2G 云服务全球[VPS测评]
- HostSailor→$2 月 KVM-1GB 30GB 1TB 荷兰&全球[VPS测评]
- 大容量便宜 VPS 汇总推荐→5 美元 月左右 空间 500GB 以上虚拟空间(主机)
- AlphaRacks→已合并 WootHosting NFPHostin全球[VPS测评]
- Online→€1.99 月 C2350 4GB 内存 1TB 硬盘 不全球[VPS测评]
- 练手专用 $7 年 2G 内存 30G SSD 2T 流量 100Mbp全球[VPS测评]
- 主机推荐:WOPUS IDC 也许是最靠谱的虚拟主机全球[VPS测评]
- Weebly网站迁移到WordPress的实操上手。全球[VPS测评]
- 什么是Bootstrap?全球[VPS测评]
- 如何设置指定路径跳转指定域名?全球[VPS测评]
- 云计算拯救互联网巨头:谁抢跑,谁追赶?全球[VPS测评]
- 什么是Bootstrap?全球[VPS测评]
- 亚马逊卖家与广告流量之间的博弈才刚刚开始?品牌卖家如何冲破广告之困...全球[VPS测评]
- 企鹅小屋:香港ntt vps,大带宽直连,1核/1G/2T流量/半年15香港VPS[主机]
- 长三角地区的算力需求规模到底有多大?全球[VPS测评]
- Hostkvm:香港/韩国CN2云服务器 大带宽VPS 2核4G,$7.韩国VPS[主机]
- 情画数据:香港沙田CN2云服务器,2核/2G/5M带宽,年付200元香港VPS[主机]
- sugarhosts糖果主机黑五:VPS服务器5折,最低月付24.5元,香港VPS[主机]
- 6种样式社交论坛网站HTML5模板 - Social全球[VPS测评]
- 傲闪云vps,1核1G低至10元起,国内高防/香港CN2/美国CN2/美美国VPS[主机]
- edgeNAT:2021元旦vps促销_全场韩国/美国/香港VPS低至7韩国VPS[主机]
- 亿速云“双11”上云狂欢大促 高防云服务器、裸金属服务器优惠套餐全球[VPS测评]
- uuuvps:香港VPS低至97元/年,CN2+bgp网络,香港机房VP香港VPS[主机]
- 阿里行癫:如何理解当下的云计算全球[VPS测评]
- 极光KVM:新上香港CN2VPS,终身6折优惠,1核/1G/5Mbps,香港VPS[主机]
- 香港的云服务器值得租用吗?有什么好处?香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-142819.html











