首页 > WordPress > WordPress hack:如何在每篇博文上加上作者的信息

WordPress hack:如何在每篇博文上加上作者的信息

2009年11月3日

如果你的博客上由几人负责更新发布或者写作的,那么你一定可以用得到这个WordPress hack。当然一个人的也上有用的。

把博文的作者的信息添加到博文某处,不仅可以宣传作者,同时,浏览者也能看到更多的信息,具有更大的粘性。

下面还是来说怎么办吧!

首先,打开functions.php,复制和粘贴以下代码:

function get_author_bio ($content=”){
    global $post;

    $post_author_name=get_the_author_meta(“display_name”);
    $post_author_description=get_the_author_meta(“description”);
    $html=”<div class=’clearfix’ id=’about_author’>\n”;
    $html.=”<img width=’80′ height=’80′ class=’avatar’ src=’http://www.gravatar.com/avatar.php?gravatar_id=”.md5(get_the_author_email()). “&default=”.urlencode($GLOBALS['defaultgravatar']).”&size=80&r=PG’ alt=’PG’/>\n”;
    $html.=”<div class=’author_text’>\n”;
    $html.=”<h4>Author: <span>”.$post_author_name.”</span></h4>\n”;
    $html.= $post_author_description.”\n”;
    $html.=”</div>\n”;
    $html.=”<div class=’clear’></div>\n”;
    $content .= $html;
    }

    return $content;
}

add_filter(‘the_content’, ‘get_author_bio’);
接下来在你的模板里调用设定的函数即可。

注:其实还有另外的实现方法,飞鱼的声纳采用的上在Users > Your Profile添加完全信息,然后在single.php中插入使用

 

调用,详细情况可以去飞鱼的声纳看一看
编译:博客海

原文地址:wprecipes

WordPress ,

  1. 2009年11月4日16:49 | #1

    这个不错,呵呵

  2. 2009年11月4日21:46 | #2

    不感冒啊。。。

  3. 2009年11月5日16:14 | #3

    @ooaixt
    谢谢哦!希望对你有帮助!
    @Tigerw
    看点感冒的吧?顺便问下,伱对什么感冒?

  1. 目前还没有任何 trackbacks 和 pingbacks.