Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to get author information in my header.php.

This is what I use to display the name and it works like a charm:

<?php $author_id=$post->post_author; ?><?php echo the_author_meta( 'display_name' , $author_id ); ?>

I also wanted to get the author's URL so I changed the code to

<?php $author_id=$post->post_author; ?><?php echo the_author_meta( 'user_url' , $author_id ); ?>

but this doesn't work.

share|improve this question
    
What are you hoping to get the author for? Which post? –  bungeshea_ Jan 9 '13 at 9:19

3 Answers 3

I just put a piece of code from author.php file of TwentyTwelve theme:

<?php
    /* Queue the first post, that way we know
     * what author we're dealing with (if that is the case).
     *
     * We reset this later so we can run the loop
     * properly with a call to rewind_posts().
     */
    the_post();
?>

<header class="archive-header">
    <h1 class="archive-title"><?php printf( __( 'Author Archives: %s', 'twentytwelve' ), '<span class="vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( "ID" ) ) ) . '" title="' . esc_attr( get_the_author() ) . '" rel="me">' . get_the_author() . '</a></span>' ); ?></h1>
</header><!-- .archive-header -->

<?php
    /* Since we called the_post() above, we need to
     * rewind the loop back to the beginning that way
     * we can run the loop properly, in full.
     */
    rewind_posts();
?>

Pay attention to how they get an author posts link. At the beginning they call the_post function outside the main loop to fetch first post. Then they get author information, like posts URL and display name. And finally they call rewind_posts function to reset loop.

You can use the same technique in your header.php file.

share|improve this answer

the_author_meta( 'user_url' ) will retrieve the website URL as set in the author's profile. You need to use the_author_meta( 'url' ) to display a link to the author post archive:

<?php
global $post;
$author_id = $post->post_author;
the_author_meta( 'url' , $author_id );
?>

Also note that you don't need to echo anything, as the_author_meta() already displays it for you.

share|improve this answer
    
It is giving me page permalink –  vaibhav Jan 9 '13 at 8:55
    
See my updated answer –  bungeshea_ Jan 9 '13 at 9:27
    
still the same giving me page permalink –  vaibhav Jan 9 '13 at 14:27

You can use get_the_author_link() function to get the url pointing to the author.

Also you can use the_author_link() to display the author link.

Edit

You might get help with this.

Ex.

<?php
global $post;
$author_id=$post->post_author;
$field='user_url';
the_author_meta( $field, $author_id );
?>
share|improve this answer
    
as i said i am using the codes outside the loop –  vaibhav Jan 9 '13 at 8:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.