WordPress – 在每一个文章内容末尾都加一个作者信息展示框
原创文章,作者:StubbornHuang,如若转载,请注明出处:《WordPress – 在每一个文章内容末尾都加一个作者信息展示框》https://www.stubbornhuang.com/1005/
类似于本文内容最后的个人作者信息展示框,我们可以通过以下的步骤进行添加。
1 思路
在wordpress网站展示文章内容时添加一个函数钩子wp_author_info_box,在钩子函数中对文章内容进行修改,在文章末尾加入html代码从而完成个人作者信息的添加。
2 修改步骤
2.1 修改主题function.php
在当前主题的function.php中增加以下代码:
function wp_author_info_box( content ) {
globalpost;
// 检测文章与文章作者
if ( is_single() && isset( post->post_author ) ) {
// 获取作者名称display_name = get_the_author_meta( 'display_name', post->post_author );
// 如果没有名称,使用昵称
if ( empty(display_name ) )
display_name = get_the_author_meta( 'nickname',post->post_author );
// 作者的个人信息
user_description = get_the_author_meta( 'user_description',post->post_author );
// 获取作者的网站
user_website = get_the_author_meta('url',post->post_author);
// 作者存档页面链接
user_posts = get_author_posts_url( get_the_author_meta( 'ID' ,post->post_author));
if ( ! empty( display_name ) )author_details = '<div class="author-name">关于本站站长 ' . display_name . '</div>';
if ( ! empty(user_description ) )
// 作者头像
author_details .= '<div class="author-details">' . get_avatar( get_the_author_meta('user_email') , 90 ) . nl2br(user_description ). '</div>';
// 在文章后面添加作者信息
content =content . '<footer class="author-bio-section" >' . author_details . '</footer>';
}
returncontent;
}
// 添加过滤器
add_action( 'the_content', 'wp_author_info_box' );
// 允许HTML
remove_filter('pre_user_description', 'wp_filter_kses');
2.2 修改主题css样式文件
在主题的css样式文件style.css文件中加入信息框的样式代码:
.author-bio-section {
background: #fff;
float: left;
width: 100%;
margin: 10px 0;
padding: 15px;
border: 1px dashed #7B68EE;
}
.author-name {
font-size: 15px;
font-weight: bold;
margin: 0 0 5px 0;
}
.author-details img {
float: left;
width: 48px;
height: auto;
margin: 5px 15px 0 0;
}
学过html、css的大概都看的懂吧。
如果您觉得对您有帮助,可以请站长喝一杯咖啡哦!
用支付宝或者微信扫描二维码
对站长进行赞助
![]() 支付宝扫一扫 |
![]() 微信扫一扫 |
金额随意,礼清义重
当前分类随机文章推荐
- WordPress - 在编辑文章发布时弹出是否发布提醒框
- WordPress - 纯代码在文章内容末尾添加当前文章同一分类下的随机推荐文章
- WordPress - 添加网页三角网粒子背景 Canvas-nest.js
- 网站个性化 - 添加人形时钟 honehone_clock.js
- WordPress - Windows使用PhpStudy本地部署WordPress
- WordPress - 插件WP Editor.md 在网站更换为https后无法正确加载
- WordPress - 修改管理后台登录地址,防止恶意爆破
- WordPress - 禁用XML-RPC接口,禁止访问xmlrpc.php,避免DDOS攻击,防止暴力破解
- WordPress - 查看别人的网站是用的WordPress的哪个主题
- WordPress - 站点底部显示站点运行时间
全站随机文章推荐
- VPS - 使用XShell连接VPS
- WordPress - robots.txt
- WordPress - 为文章增加评论才可查看相关隐藏内容的代码
- 资源分享 - Fluid Simulation for Computer Graphics, First Edition英文高清PDF下载
- OpenCV - 打开摄像头并用窗口显示摄像头的内容
- WordPress - 增加百度统计代码
- Python3爬虫 - 下载反盗链图片的方式
- 工具推荐 - 数学公式在线编辑并实时转换为Latex/Katex/MathML
- 资源分享 - Real-Time Rendering, Third Edition 英文原版Pdf下载
- 资源下载 - Physically Based Rendering - From Theory to Implementation 3rd edition(英文版) PDF下载
赞赞赞!
哈哈哈哈哈哈哈!