Saturday, May 21, 2016

WordPress get Author info from post ID

If you want to get the Author information such as name, profile image and name from post ID then it can be retrieved in the following way.

<?php $author_id=$post->post_author; ?>

Now suppose you want to get the Author Avatar. The avatar is fetched in the following way.

<img src="<?php echo the_author_meta( 'avatar' , $author_id ); ?> " width="140" height="140" class="avatar" alt="<?php echo the_author_meta( 'display_name' , $author_id ); ?>" />

This will display the author avatar.

To display the author name use the following code.

<?php echo the_author_meta( 'user_nicename' , $author_id ); ?>


This will display the author name.

No comments:

Post a Comment

MS SQL : How to identify fragmentation in your indexes?

Almost all of us know what fragmentation in SQL indexes are and how it can affect the performance. For those who are new Index fragmentation...