最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Display author's name and avatar in post's sidebar

programmeradmin3浏览0评论

I'd like to display the post author's name and avatar on posts sidebar but I can't find any info on it.

Is there a shortcode or piece of code to do this ?

Thanks for your help

I'd like to display the post author's name and avatar on posts sidebar but I can't find any info on it.

Is there a shortcode or piece of code to do this ?

Thanks for your help

Share Improve this question asked Sep 10, 2015 at 8:08 Graham SlickGraham Slick 2712 gold badges4 silver badges13 bronze badges 3
  • Write your own widget :-) – Pieter Goosen Commented Sep 10, 2015 at 8:16
  • Well I'd love to, but I have no idea how to do this ;) Any function I should use ? – Graham Slick Commented Sep 10, 2015 at 8:20
  • Use get_queried_object()->post_author in single page view in the widget to get the post author ID and then take it from there – Pieter Goosen Commented Sep 10, 2015 at 8:22
Add a comment  | 

3 Answers 3

Reset to default 2

Display author's avatar and name in single page sidebar. Add this code in sidebar.php or single.php

if ( is_singular( 'post' ) ) {
    echo get_avatar( get_the_author_meta( 'user_email' ), 75 );
    echo get_the_author_meta( 'display_name' );
}

Here 75 number is the avatar size.

I hope it will help you.

if you are using it in Loop then :

You can display author name by using

<?php $author = get_the_author();
   echo $author; ?>

and you can display post author avatar using

<?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?>

you can change 32 size to whatever your need.

Hope this will work for you.

thanks

Display author's name and avatar in Post page and single post page sidebar. Put this code in sidebar.php

        if(is_home() || is_single()){
           echo get_avatar( $post->post_author,'100');
           echo get_the_author($post->post_author);
        }

I hope useful.

发布评论

评论列表(0)

  1. 暂无评论