教你在WordPress文章页面添加作者信息模块


怎样在wordpress文章显示添加一组作者信息模块呢,方便显示作用的一系列信息,比如名称,昵称,个人简介,网站,头像等信息,测速网分享一段实用的作用信息函数,给大家,可以方便的使用起来。只需要将以上代码添加到wordpress当前主题的functions.php文件中:

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253function 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 .= '查看 ' . $display_name . ' 所有文章';// 检查作者在个人资料中是否填写了网站if ( ! empty( $user_website ) ) {// 显示作者的网站链接$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');

同时需要在wordpress主题文件中添加对应的css样式到style.css样式表中。

12345678910111213141516171819.author-bio-section {background: #fff;float: left;width: 100%;margin: 10px 0;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;}

作者信息模块的功能就完成了,这个功能可以自动在文章内容下面调用信息,是不是很方便呢


上一篇:WPSeku安装与使用:WordPress 安装漏洞扫描器

下一篇:WordPress文章内容必备函数调用详解


Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器