纯代码为WordPress文章结尾增加作者简介模块

文章目录
  • 一、添加作者信息板块:
  • 二、添加CSS样式:
  • 三、添加个人信息:
  • 四、效果显示:

很多Wordpress主题都有作者简介模块,一般位于文章结尾处,可以在每篇文章结尾对作者进行简单的简介,提高作者曝光率。当然没有此功能的可以通过相关插件来实现,但本站一直不提倡使用大量插件,因为大量插件的使用会增加主机负担。那么我们是不是可以纯代码为自己的WordPress文章尾部增加作者简介模块呢?答案是当然可以!下面本站就为大家简介一个方法,只需通过两段简单代码就可以为自己的博客文章尾部增加作者简介模块。

一、添加作者信息板块:

1、首先我们在主题中找到functions.php文件,并添加下面代码。

//添加作者信息板块——www.wn789.com function wpb_author_info_box( $content ) { global $post; // Detect if it is a single post with a post author if ( 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 name if ( 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 = '

About ' . $display_name . '

'; if ( ! empty( $user_description ) ) // Author avatar and bio $author_details .= '

' . get_avatar( get_the_author_meta('user_email') , 90 ) . nl2br( $user_description ). '

'; $author_details .= ''; } else { // if there is no author website then just close the paragraph $author_details .= ''; } // Pass all this info to post content $content = $content . '' . $author_details . ''; } return $content; } // Add our function to the post content filter add_action( 'the_content', 'wpb_author_info_box' ); // Allow HTML in author bio section remove_filter('pre_user_description', 'wp_filter_kses');

2、在上面代码中我们可以根据自己需要进行简单修改。下面本站已经列出:

  • “$author_details .= ‘

    点此给本站发送邮件’; ”代码中的网址和汉字可以根据自己情况进行修改。

  • “$author_details .= ‘ | 广告投放QQ490898739’; ”代码中的网址和汉字可以根据自己情况进行修改。

二、添加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; }

三、添加个人信息:

在“用户”-“我的个人资料”-个人说明栏填写你要显示的信息即可。这个信息可以根据自己需要填写,可以是简介自己、也可以是广告内容。

四、效果显示:

下图是本站添加作者信息板块后的效果。

推荐站内搜索:https代理ip双线空间、网站虚拟主机空间、免费服务器香港ip代理、广州网站备案、查询域名是否备案游戏服务器防御、备案查询网、香港主机高防、