教你在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 安装漏洞扫描器
声卡驱动正常但是没有声音如何办?声卡驱动正常没声音的解决方法
英伟达显卡驱动如何退回到原来版本?英伟达显卡驱动退回到原来版
重装系统,电脑只有一个C盘如何创建分区
Defender提示错误应用程序MsMpEng.exe无法启动
电脑无法启动或仍在加载如何办?电脑无法启动或仍在加载的解决方
打印机驱动如何卸载删除?卸载打印机驱动干净的教程
电脑没网如何安装网卡驱动?教你没网如何安装网卡驱动的方法
系统32位和62位如何选择:详解它们之间的差异
电脑文件删不掉如何办?四种方法解决
任务管理器快捷键有哪些?任务管理器快捷键大全