WordPress – 在每一个文章内容末尾都加一个作者信息展示框
本文作者:StubbornHuang
版权声明:本文为站长原创文章,如果转载请注明原文链接!
原文标题:WordPress – 在每一个文章内容末尾都加一个作者信息展示框
原文链接:https://www.stubbornhuang.com/1005/
发布于:2020年12月03日 22:47:55
修改于:2020年12月03日 22:56:16

类似于本文内容最后的个人作者信息展示框,我们可以通过以下的步骤进行添加。
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的大概都看的懂吧。
当前分类随机文章推荐
- WordPress - 在文章页顶部加入百分比阅读滚动进度条 阅读828次,点赞2次
- WordPress - 在用户登录页面添加自定义提示信息 阅读1492次,点赞0次
- WordPress - 防止用户在登录页面重复点击登录按钮造成重复登录 阅读584次,点赞0次
- 网站个性化 - 添加人形时钟 honehone_clock.js 阅读2933次,点赞0次
- WordPress - 文章自定义字段post_meta添加、更新、删除、获取操作 阅读1026次,点赞0次
- WordPress - 用户修改密码/邮箱时禁止向管理员/用户发送通知邮件 阅读772次,点赞0次
- WordPress - 禁止非管理员登录后台 阅读1680次,点赞0次
- WordPress - 在文章被复制时弹出弹窗提示转载注明原创 阅读3035次,点赞2次
- WordPress - 获取某个用户发表的评论数量 阅读1828次,点赞0次
- WordPress - 支持用户注册时使用中文名 阅读1876次,点赞0次
全站随机文章推荐
- WordPress - 为文章增加评论才可查看相关隐藏内容的代码 阅读2541次,点赞3次
- C++读取Shp文件并将Shp转化为DXF 阅读3043次,点赞1次
- C++ - 在Windows/Linux上创建单级目录以及多级目录的跨平台方法 阅读925次,点赞0次
- C++ - 使用ffmpeg读取视频旋转角度并使用OpenCV根据旋转角度对视频进行旋转复原 阅读1708次,点赞0次
- 资源分享 - Microsoft Voxelized Upper Bodies – A Voxelized Point Cloud Dataset下载 阅读2699次,点赞0次
- 资源分享 - 交互式计算机图形学:基于OpenGL着色器的自顶向下方法(第六版),Interactive Computer Graphics - A top-down approach with shader-based OpenGL(Six 6th Edition)中文版PDF下载 阅读597次,点赞0次
- 资源分享 - Graphics Gems III 英文高清PDF下载 阅读2001次,点赞0次
- mciSendCommand在Win10上奔溃的问题解决/循环播放音乐 阅读2831次,点赞0次
- WordPress - 在用户登录页面添加自定义提示信息 阅读1492次,点赞0次
- 计算几何 - 求解两个三维向量之间的三维旋转矩阵 阅读1148次,点赞0次
赞赞赞!
哈哈哈哈哈哈哈!