WordPress: get author info from post id

前端 未结 3 1887
后悔当初
后悔当初 2020-12-25 10:06

Or even the author id from the post id. I am trying to return the author meta (author page link and avatar) in the sidebar of a single post page (outside of the post loop).

相关标签:
3条回答
  • 2020-12-25 10:19

    If you want it outside of loop then use the below code.

    <?php
    $author_id = get_post_field ('post_author', $cause_id);
    $display_name = get_the_author_meta( 'display_name' , $author_id ); 
    echo $display_name;
    ?>
    
    0 讨论(0)
  • 2020-12-25 10:19
    <?php
      $field = 'display_name';
      the_author_meta($field);
    ?>
    

    Valid values for the $field parameter include:

    • admin_color
    • aim
    • comment_shortcuts
    • description
    • display_name
    • first_name
    • ID
    • jabber
    • last_name
    • nickname
    • plugins_last_view
    • plugins_per_page
    • rich_editing
    • syntax_highlighting
    • user_activation_key
    • user_description
    • user_email
    • user_firstname
    • user_lastname
    • user_level
    • user_login
    • user_nicename
    • user_pass
    • user_registered
    • user_status
    • user_url
    • yim
    0 讨论(0)
  • 2020-12-25 10:29

    I figured it out.

    <?php $author_id=$post->post_author; ?>
    <img src="<?php the_author_meta( 'avatar' , $author_id ); ?> " width="140" height="140" class="avatar" alt="<?php echo the_author_meta( 'display_name' , $author_id ); ?>" />
    <?php the_author_meta( 'user_nicename' , $author_id ); ?> 
    
    0 讨论(0)
提交回复
热议问题