WordPress – 在每一个文章内容末尾都加一个作者信息展示框
类似于本文内容最后的个人作者信息展示框,我们可以通过以下的步骤进行添加。
1 思路
在wordpress网站展示文章内容时添加一个函数钩子wp_author_info_box,在钩子函数中对文章内容进行修改,在文章末尾加入html代码从而完成个人作者信息的添加。
2 修改步骤
2.1 修改主题function.php
在当前主题的function.php中增加以下代码:
function wp_author_info_box( $content ) {
global $post;
// 检测文章与文章作者
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>';
}
return $content;
}
// 添加过滤器
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的大概都看的懂吧。
本文作者:StubbornHuang
版权声明:本文为站长原创文章,如果转载请注明原文链接!
原文标题:WordPress – 在每一个文章内容末尾都加一个作者信息展示框
原文链接:https://www.stubbornhuang.com/1005/
发布于:2020年12月03日 22:47:55
修改于:2023年06月26日 22:03:39
当前分类随机文章推荐
- WordPress - 应对暴力破解登录和规避DDOS的几种方法 阅读2615次,点赞0次
- WordPress - 网站加载自定义字体的最佳方式 阅读169次,点赞1次
- WordPress - 异步发送邮件,解决发送邮件阻塞耗时的问题 阅读502次,点赞0次
- WordPress - 增加百度统计代码 阅读3330次,点赞0次
- WordPress - Windows使用PhpStudy本地部署WordPress 阅读4066次,点赞0次
- WordPress - $Post WP_Post对象的属性 阅读2850次,点赞0次
- WordPress - 发送邮件很慢的解决办法 阅读836次,点赞1次
- WordPress - get_sidebar函数,加载主题侧边栏模板 阅读1109次,点赞0次
- WordPress - 利用Revolvermaps在首页实时显示访客3D地球 阅读3631次,点赞1次
- WordPress - 在后台管理面板添加禁止某一个用户登录的功能 阅读416次,点赞0次
全站随机文章推荐
- 资源下载 - Physically Based Rendering - From Theory to Implementation 3rd edition(英文版) PDF下载 阅读14717次,点赞4次
- 资源分享 - 深度学习实战(杨云杜飞 清华大学出版社)高清pdf下载 阅读2733次,点赞0次
- 资源分享 - 机器学习 (西瓜书) 周志华著PDF下载 阅读35143次,点赞31次
- 解决Python爬虫在爬资源过程中使用urlretrieve函数下载文件不完全且避免下载时长过长陷入死循环,并在下载文件的过程中显示下载进度 阅读4391次,点赞0次
- 资源分享 - Practical Linear Algebra - A Geometry Toolbox , Third Edition 英文高清PDF下载 阅读1408次,点赞0次
- C++11 - 使用std::codecvt进行字符编码转换需要注意的时间效率问题 阅读2525次,点赞2次
- C++ – 字节数组byte[]或者unsigned char[]与float的相互转换 阅读2876次,点赞0次
- Python - 字典dict遍历方法总结 阅读896次,点赞0次
- Python - 运算符/、//和%的含义与区别 阅读698次,点赞0次
- 资源分享 - An Introduction to Ray Tracing 英文高清PDF下载 阅读1362次,点赞0次
赞赞赞!
哈哈哈哈哈哈哈!