所有分类
  • 所有分类
  • WordPress主题
  • WordPress插件
  • 源码
  • 软件
  • 主题教程

WordPress如何在文章末尾添加作者信息框?

作者信息框

可以实现在文章的末尾自带添加一个作者信息框,进行一些简单的自我介绍,具体参考本站文章底部。

在主题根目录下的functions.php文件中的<?php下添加以下代码:

function wp_author_info_box( $content ) {      global $post;      // 检测文章与文章作者      if ( is_single() &amp;&amp; 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 = '<div class="author-name">关于 ' . $display_name . '</div>';          if ( ! empty( $user_description ) )          // 作者头像          $author_details .= '<div class="author-details">' . get_avatar( get_the_author_meta('user_email') , 90 ) . nl2br( $user_description ). '</div>';          $author_details .= '<div class="author-links"><a href="'. $user_posts .'">查看 ' . $display_name . ' 所有文章</a>';          // 检查作者在个人资料中是否填写了网站          if ( ! empty( $user_website ) ) {          // 显示作者的网站链接          $author_details .= ' | <a href="' . $user_website .'" target="_blank" rel="nofollow">网站</a></div>';          } else {              // 如果作者没有填写网站则不显示网站链接              $author_details .= '</div>';          }          // 在文章后面添加作者信息          $content = $content . '<footer class="author-bio-section" >' . $author_details . '</footer>';      }      return $content;  }  // 添加过滤器  add_action( 'the_content', 'wp_author_info_box' );  // 允许HTML  remove_filter('pre_user_description', 'wp_filter_kses');

 

stylee.css美化代码:

.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;  }

如果stylee.css不生效的话,可以像我一样把他放在fonctions.php

WordPress如何在文章末尾添加作者信息框?-小小资源铺

免责声明:
使用本站资源的用户均应仔细阅读本声明。用户使用本站资源的行为将被视为对本声明全部内容的认可。
1、本站资源大部分搜集于网络,整理并分享。用户可自行搜索在其他地方下载,也可选择在本站下载。如果侵犯了您的合法权益,请联系:diy945945@111.com 及时删除。本站资源仅用于研究、学习之用,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担。
2、本站对发布的资源不能保证其完整性、安全性和可用性。请您在下载后自行检查。您在使用过程中遇到的任何问题与本站无关。
3、注册本站以及在本站充值、开通会员等消费行为仅作为用户本人对本站的友情赞助,均为用户本人的自愿行为。相当于您是自愿赞助本站的服务器以及运营维护费用,而不是购买本站的任何服务与资源,请知悉!!!
4、本站资源资源采用网盘分享,如链接失效,请及时联系。
5、原文链接:https://www.xxziyuan.top/3216.html,转载请注明出处。
0

评论0

请先
Octolooks Scrapes-可视化采集WordPress插件 v2.3
Octolooks Scrapes-可视化采集WordPress插件 v2.3
9分钟前 有人购买 去瞅瞅看

站点公告

专注WordPress-源码-实用软件分享!

WordPress网站搭建联系qq:429413218

显示验证码
没有账号?注册  忘记密码?