在WordPress 文章未尾自动添加一个作者信息框

在WordPress 文章未尾自动添加一个作者信息框

如果想在WordPress文章的未尾,添加文章作者的相关信息,下面一段代码可以帮助方便在文章中添加一个作者的信息框。

将代码添加到当前主题functions.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 = '
关于 ' . $display_name . '
'; if ( ! empty( $user_description ) ) // 作者头像 $author_details .= '
' . get_avatar( get_the_author_meta('user_email') , 90 ) . nl2br( $user_description ). '
'; $author_details .= ''; } else { // 如果作者没有填写网站则不显示网站链接 $author_details .= '
'; } // 在文章后面添加作者信息 $content = $content . '
' . $author_details . '
'; } return $content;}// 添加过滤器add_action( 'the_content', 'wp_author_info_box' );// 允许HTMLremove_filter('pre_user_description', 'wp_filter_kses');

再将配套的CSS添加到主题样式文件style.css中:

.author-bio-section { background: #fff; float: left; width: 100%; padding: 15px; border: 1px dashed #ccc;}.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;}

演示效果在WordPress 文章未尾自动添加一个作者信息框插图走客Mac

 

声明:本站所有软件资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
Mac软件

Downie 4.2.2 Mac中文激活版

2021-4-9 10:00:13

Mac软件

QLab 5.2 Mac激活版

2023-8-5 8:10:18

0 条回复A文章作者M管理员
    暂无讨论,说说你的看法吧
个人中心
今日签到
有新私信 私信列表
搜索