純代碼為WordPress文章結尾增加作者介紹模塊

很多Wordpress主題都有作者介紹模塊,一般位于文章結尾處,可以在每篇文章結尾對作者進行簡單的介紹,提高作者曝光率。當然沒有此功能的可以通過相關插件來實現(xiàn),但傲云一直不提倡使用大量插件,因為大量插件的使用會增加服務器負擔。那么我們是不是可以純代碼為自己的WordPress文章尾部增加作者介紹模塊呢?答案是當然可以!下面蝸牛就為大家介紹一個方法,只需通過兩段簡單代碼就可以為自己的博客文章尾部增加作者介紹模塊。

一、添加作者信息板塊:

1、首先我們在主題中找到functions.php文件,并添加下面代碼。

//添加作者信息板塊——www.lrracing.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  target="_blank">點此加入電報群(推薦)</a>';
// Check if author has a website in their profile
if ( ! empty( $user_website ) ) {
// Display author website link
$author_details .= ' | <a  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、在上面代碼中我們可以根據(jù)自己需要進行簡單修改。下面已經(jīng)列出:

$author_details .= '<p?class="author_links"><a?; $author_details .= ' | <a?;代碼中的網(wǎng)址和漢字可以根據(jù)自己情況進行修改。

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

三、添加個人信息:

在“用戶”-“我的個人資料”-個人說明欄填寫你要顯示的信息即可。這個信息可以根據(jù)自己需要填寫,可以是介紹自己、也可以是廣告內容。

四、效果顯示:

下圖是添加作者信息板塊后的效果。

贊(0)
版權聲明:本文采用知識共享 署名4.0國際許可協(xié)議 [BY-NC-SA] 進行授權, 轉載請注明出處。
文章名稱:《純代碼為WordPress文章結尾增加作者介紹模塊》
文章鏈接:http://www.lrracing.com/5993.html
【聲明】:國外主機測評僅分享信息,不參與任何交易,也非中介,所有內容僅代表個人觀點,均不作直接、間接、法定、約定的保證,讀者購買風險自擔。一旦您訪問國外主機測評,即表示您已經(jīng)知曉并接受了此聲明通告。
【關于安全】:任何 IDC商家都有倒閉和跑路的可能,備份永遠是最佳選擇,服務器也是機器,不勤備份是對自己極不負責的表現(xiàn),請保持良好的備份習慣。