纯代码为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
- PacificRack→$8.88 年 KVM-400MB 12GB 1全球[VPS测评]
- weui textarea 字数限制以及动态显示输入字数的方法(jque全球[VPS测评]
- 超低价 趣味云→香港 CN2 线路 1G 内存 20G SSD 3M 带香港VPS[主机]
- MoeCloud→25 元 月特价机补货 CN2 GIA 线路 可以看奈全球[VPS测评]
- 有点卡-OLVPS 波兰特 cera 机房便宜 KVM VPS 服务器优全球[VPS测评]
- 云创网络→55.2 元 月 512MB 内存 10GB SSD 空间 1虚拟空间(主机)
- 阿里云建站首选轻量应用服务器 香港节点 30M 峰值带宽¥864 3 年香港VPS[主机]
- CentOS 下 iptables 防火墙开放 80 端口全球[VPS测评]
- VPS 推荐 搬瓦工→DC9 强势回归 1Gbps 洛杉矶 CN2 G全球[VPS测评]
- Wholesaleinternet→独立服务器月付 10 美元起 100独立服务器[U]
- 促销 iON→圣何塞线路改善 8 折优惠一个月 1 核 2G 50G S全球[VPS测评]
- 搬瓦工→新增 10Gbps 带宽的 cn2 gia 线路 VPS 移动+全球[VPS测评]
- OG协议对博客Google SEO优化有什么帮助?全球[VPS测评]
- 主机推荐:Fastcomet虚拟主机全球[VPS测评]
- 其云否特价 VPS 768M内存,35G硬盘,2T流量,电信双向CN2G全球[VPS测评]
- 如何解决WordPress后台登录显示重定向次数过多全球[VPS测评]
- 美国便宜 VPS 春节促销汇总,最低$7.5/年。美国VPS[主机]
- 谁黑了 HostSolutions.ro?hostsolutions.r全球[VPS测评]
- Linode正式更换至新的云管理面板全球[VPS测评]
- JustHost新上美国达拉斯机房,八折优惠,200M带宽不限流量,月付美国VPS[主机]
- 滴盾双十二东莞BGP独立服务器16核32G内存500G流量G口50m带宽独立服务器[U]
- DMIT.io → 2G 内存 20G SSD 无限流量 200M带宽 全球[VPS测评]
- 2019黑五: PacificRack → 2C 1G RAM 30G全球[VPS测评]
- 加拿大以“国安”为由禁止华为、中兴参与5G建设全球[VPS测评]
- 8K超高清记录中国空间站凌月:天和核心舱与问天实验舱组成“土”字结构虚拟空间(主机)
- 香港云服务器的优势有哪些方面香港VPS[主机]
- 极光kvm怎么样?香港大带宽VPS促销1核1G内存19元/月起,5G防御香港VPS[主机]
- 快云科技:2核2G3M香港云BGP/新界CN2云服务器,月付33元香港VPS[主机]
- TabbyCloud:1核512MB内存/20GB/500GB流量/KV香港VPS[主机]
- SugarHosts,美国云服务器,洛杉矶cn2中美极速专线,香港建站服美国VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-129305.html











