站长视角
用户至上

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

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

一、添加作者信息板块:

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

//添加作者信息板块——www.veidc.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 = '<p class="author_name">关于 ' . $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 rel="nofollow" href="https://www.sshce.com/go?url=aHR0cHM6Ly90Lm1lL3ZlaWRj" target="_blank">点此加入电报群(推荐)</a>';
// Check if author has a website in their profile
if ( ! empty( $user_website ) ) {
// Display author website link
$author_details .= ' | <a rel="nofollow" href="https://www.sshce.com/go?url=aHR0cHM6Ly9zaGFuZy5xcS5jb20vd3BhL3F1bndwYT9pZGtleT0wNDU0ZDk5OTMzZTVlNWUwNDU0OThhNDQyNTUzNTljNWUxYmU0ZTNmMThjNDUyMmFkNDBiY2QzMDZjNmIwZDQ4" target="_blank" rel="nofollow">QQ交流群:281562063</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 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 .= '<p class="author_links"><a rel="nofollow" href="https://www.sshce.com/go?url=aHR0cDovL21haWwucXEuY29tL2NnaS1iaW4vcW1fc2hhcmU/dD1xbV9tYWlsbWUmYW1wO2VtYWlsPWlhb2R1bkBxcS5jb20=" target="_blank">点此给VEIDC测评发送邮件</a>'; $author_details .= ' | <a rel="nofollow" href="https://www.sshce.com/go?url=aHR0cHM6Ly93cGEucXEuY29tL21zZ3JkP3Y9MyZhbXA7dWluPTk1OTEwNTAmYW1wO3NpdGU9cXEmYW1wO21lbnU9eWVz" target="_blank" rel="nofollow">广告投放QQ:9591050</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;
}

三、添加个人信息:

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

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

四、效果显示:

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

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

赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权, 转载请注明出处。
文章名称:《纯代码为WordPress文章结尾增加作者介绍模块》
文章链接:https://www.sshce.com/5993.html
【声明】:国外主机测评仅分享信息,不参与任何交易,也非中介,所有内容仅代表个人观点,均不作直接、间接、法定、约定的保证,读者购买风险自担。一旦您访问国外主机测评,即表示您已经知晓并接受了此声明通告。
【关于安全】:任何 IDC商家都有倒闭和跑路的可能,备份永远是最佳选择,服务器也是机器,不勤备份是对自己极不负责的表现,请保持良好的备份习惯。
香港110M(含10M CN2)大带宽独服限量促销,香港E3-8G-1T硬盘-3IP,月付仅799!

登录

找回密码

注册