Get_the_author不返回作者姓名

时间:2015-07-27 09:12:25

标签: php wordpress

我试图在单页上显示元内容。但get_the_author()没有显示。以下代码的结果是

  

撰写于2015年7月14日

它应该显示

  

admin 于2015年7月14日撰写

任何人都知道我错过了什么?这是代码:

function mano_posted_on() {
    $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
    if (get_the_time('U') !== get_the_modified_time('U')) {
        $time_string.= '<time class="updated" datetime="%3$s">%4$s</time>';
    }

    $time_string = sprintf(
            $time_string,
            esc_attr(get_the_date('c')),
            esc_html(get_the_date()),
            esc_attr(get_the_modified_date('c')),
            esc_html(get_the_modified_date())
    );

    printf(
            __('<span class="byline">Written by %1$s</span><span class="posted-on">on %2$s</span>', 'mano'),
            sprintf(
                '<span class="author vcard"><a class="url fn n" href="%1$s">%2$s</a></span>',
                esc_url(get_author_posts_url(get_the_author_meta('ID'))),
                esc_html(get_the_author())
            ),
            sprintf(
                '<a href="%1$s" rel="bookmark">%2$s</a>',
                esc_url(get_permalink()),
                $time_string
            )
        );
}

2 个答案:

答案 0 :(得分:0)

  

要返回PHP而不是显示,请使用get_the_author()。   https://codex.wordpress.org/Function_Reference/the_author

因此,请尝试将get_the_author()更改为the_author()

答案 1 :(得分:0)

试试这个:

echo get_the_author($post->author_id);

将$ post设为全球。

所以它看起来像在文件顶部:

global $post;
相关问题