纯代码为WordPress文章结尾增加作者介绍模块
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

很多Wordpress主题都有作者介绍模块,一般位于文章结尾处,可以在每篇文章结尾对作者进行简单的介绍,提高作者曝光率。当然没有此功能的可以通过相关插件来实现,但蜗牛一直不提倡使用大量插件,因为大量插件的使用会增加服务器负担。那么我们是不是可以纯代码为自己的WordPress文章尾部增加作者介绍模块呢?答案是当然可以!下面蜗牛就为大家介绍一个方法,只需通过两段简单代码就可以为自己的博客文章尾部增加作者介绍模块。
一、添加作者信息板块:1、首先我们在主题中找到functions.php文件,并添加下面代码。
//添加作者信息板块——www.wn789.comfunction wpb_author_info_box( $content ) {global $post;// Detect if it is a single post with a post authorif ( is_single() && isset( $post->post_author ) ) {// Get author\'s display name$display_name = get_the_author_meta( \'display_name\', $post->post_author );// If display name is not available then use nickname as display nameif ( empty( $display_name ) )$display_name = get_the_author_meta( \'nickname\', $post->post_author );// Get author\'s biographical information or description$user_description = get_the_author_meta( \'user_description\', $post->post_author );// Get author\'s website URL$user_website = get_the_author_meta(\'url\', $post->post_author);// Get link to the author archive page$user_posts = get_author_posts_url( get_the_author_meta( \'ID\' , $post->post_author));if ( ! empty( $display_name ) )$author_details = \'<p class=\"author_name\">About \' . $display_name . \'</p>\';if ( ! empty( $user_description ) )// Author avatar and bio$author_details .= \'<p class=\"author_details\">\' . get_avatar( get_the_author_meta(\'user_email\') , 90 ) . nl2br( $user_description ). \'</p>\';$author_details .= \'<p class=\"author_links\"><a h=\"http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=wn789@vip.qq.com\" target=\"_blank\">点此给蜗牛发送邮件</a>\';// Check if author has a website in their profileif ( ! empty( $user_website ) ) {// Display author website link$author_details .= \' | <a h=\"tencent://message/?uin=490898739&Site=qq&Menu=yes\" target=\"_blank\" rel=\"nofollow\">广告投放QQ490898739</a></p>\';} else {// if there is no author website then just close the paragraph$author_details .= \'</p>\';}// Pass all this info to post content$content = $content . \'<footer class=\"author_bio_section\" >\' . $author_details . \'</footer>\';}return $content;}// Add our function to the post content filteradd_action( \'the_content\', \'wpb_author_info_box\' );// Allow HTML in author bio sectionremove_filter(\'pre_user_description\', \'wp_filter_kses\');2、在上面代码中我们可以根据自己需要进行简单修改。下面蜗牛已经列出:
“$author_details .= ‘<p class=”author_links”><a h=”http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=wn789@vip.qq.com” target=”_blank”>点此给蜗牛发送邮件</a>’; ”代码中的网址和汉字可以根据自己情况进行修改。“$author_details .= ‘ | <a h=”tencent://message/?uin=490898739&Site=qq&Menu=yes” target=”_blank” rel=”nofollow”>广告投放QQ490898739</a></p>’; ”代码中的网址和汉字可以根据自己情况进行修改。二、添加CSS样式:在主题文件中找到“main.css”文件。并把下面代码添加进去。
.author_bio_section{background: none repeat scroll 0 0 #F5F5F5;padding: 15px;border: 1px solid #ccc;}.author_name{font-size:16px;font-weight: bold;}.author_details img {border: 1px solid #D8D8D8;border-radius: 50%;float: left;margin: 0 10px 10px 0;}三、添加个人信息:
在“用户”-“我的个人资料”-个人说明栏填写你要显示的信息即可。这个信息可以根据自己需要填写,可以是介绍自己、也可以是广告内容。
四、效果显示:下图是蜗牛789添加作者信息板块后的效果。
猜你可能想看的VPS
- 百度云 - .COM 国际顶级域名新注册 45 元 首年全球[VPS测评]
- 疯狂猜成语 图猜成语狗的身体老虎的头是什么成语?全球[VPS测评]
- DNSPOD→个人专业版首年仅 18 元全球[VPS测评]
- 预售 ¥220 年 512M 内存 20G 硬盘 15Mbps 不限量 全球[VPS测评]
- Hostigger→$11.94 年 1GB 内存 10GB SSD 空虚拟空间(主机)
- JQuery 动态求和的方法全球[VPS测评]
- 便宜 VPS tmhhost→1 核 512M 内存 20G 硬盘 50全球[VPS测评]
- Domeny.pl→.pl .com.pl .edu.pl .site 全球[VPS测评]
- Digital-vm→$2.8 月 KVM-512MB 30G SSD 日本VPS[主机]
- 疯狂猜成语 图猜成语一个人隔着河在看对面的火是什么成语?全球[VPS测评]
- raksmart 四月促销,美国服务器免费送 10G 防御 美国站群买一站群服务器[IP]
- Online→€1.99 月 C2350 4GB 内存 1TB 硬盘 不全球[VPS测评]
- 解决Debian系统apt-get更新官方源失败 替换163源的方法全球[VPS测评]
- WordPress后台reCaptcha验证登录保护插件:reCaptC全球[VPS测评]
- Akkocloud德国CN2GIA VPS促销 原生IP/三网强制CN2全球[VPS测评]
- 咖啡主机2021开年 新上香港/美国CN2轻量KVM ¥46.8/季美国VPS[主机]
- .CC 域名获工信部注册备案许可全球[VPS测评]
- 昱格云 1核心 1024M内存 10G SSD 1000G单向流量 10全球[VPS测评]
- 自适应bootstrap左侧导航可关闭全球[VPS测评]
- 精编案例丨游戏行业转型升级迫在眉睫,云计算助力打造下一代游戏体验全球[VPS测评]
- 个人如何做跨境电商?全球[VPS测评]
- Linux系统下安装Java JDK全球[VPS测评]
- 尊云双十二:国内4核4G5M云服务器仅28元/月,香港CN2VPS仅84香港VPS[主机]
- 六一云:香港CN2/洛杉矶高防/CDN,“返利+折扣”双优惠,折上折送实香港VPS[主机]
- 云米科技:香港安畅/美国Cera/日本CN2机房,海外云服务器最低11元日本VPS[主机]
- jquery css3实现的进度条动画特效,带加载进度条百分比动态效果。全球[VPS测评]
- 腾讯会议故障了 提示:会议发生异常请重新加入会议全球[VPS测评]
- 六六云:美国cera机房CN2 GIA高防/香港CN2 GIA建站/CM美国VPS[主机]
- 小欢互联:洛杉矶高防vps年付138元,香港CN2线路月付8元起,1核/香港VPS[主机]
- 亿速互联怎么样?香港沙田vps,2核1G3M云主机仅98元/月,780元香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-135666.html











