无插件实现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 $4 月 512M 内存 20G SSD 10TB 流量全球[VPS测评]
- 活动 HostXen→新用户送 20 元 日本直连 7M 不限流量 VP日本VPS[主机]
- Scarlet Cloud→134.4 元 半年 256MB 内存 5G虚拟空间(主机)
- 便宜 ¥399 2 年 2 核 CPU 2G 内存 20G SSD 30香港VPS[主机]
- HostXen→香港 日本 可 DIY 配置云 XEN 架构 新客户送 日本VPS[主机]
- 疯狂猜成语 图猜成语一幅断开的竹简中间有一个义字是什么成语?全球[VPS测评]
- nat.bz→64 元 月 512MB 内存 5GB SSD 空间 20虚拟空间(主机)
- HKServerSolution→599 元 年 2 核 2G 内存 2虚拟空间(主机)
- CN2 GIA ¥148 年 256M 内存 20G SSD 10Mbp全球[VPS测评]
- hostsailor-荷兰+罗马尼亚 VPS 年付$12 256G 流量全球[VPS测评]
- OneVPS KVM VPS终身 75 折优惠码 日本VPS最低月付3.日本VPS[主机]
- 如何为WordPress网站站外链接添加自动nofollow功能全球[VPS测评]
- 私有文档、源码、软件目录列表程序:Zdir全球[VPS测评]
- WordPress插件:Username Changer直接修改用户名全球[VPS测评]
- 搭建VPS环境选择LAMP环境还是LNMP环境好全球[VPS测评]
- Contabo德国老牌商家新上新加坡数据中心,前1000名用户免设置费;美国VPS[主机]
- [信息]CloudCone 1811促销全球[VPS测评]
- 20个温暖心灵的问题,抖音,朋友圈都可以拿去发。全球[VPS测评]
- 持续高温!长沙所有初中新生停止军训!全球[VPS测评]
- 青果云怎么样?美国/香港/日本云主机 买多久送多久日本VPS[主机]
- 傲闪云vps,1核1G低至10元起,国内高防/香港CN2/美国CN2/美美国VPS[主机]
- 极光KVM:新上香港CN2VPS,终身6折优惠,1核/1G/5Mbps,香港VPS[主机]
- 常见的CN2,GIA,CIA 各个网络线路解释全球[VPS测评]
- 酷锐云:元旦钜惠_美国CN2VPS低至20元/月_1核2G香港云主机低至美国VPS[主机]
- 二三互联年末回馈:香港/美国云服务器新购特价促销,优惠码可打76折美国VPS[主机]
- 咖啡主机:享受7、8折促销 美国vps仅需15.4元/月 香港vps仅需美国VPS[主机]
- 月神云:洛杉矶CN2 GIA高防vps、香港CN2 GIA VPS全场7香港VPS[主机]
- 六六云:香港BGP云服务器/80M大带宽,月付45元起,5折优惠码可用香港VPS[主机]
- ucloud香港服务器怎么样?听听这些网友们怎么说的香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-39818.html











