Add author avatar in custom block

Posted in: Newspaper
Post count: 10

Hi, I’ve been trying to solve a small issue for days and don’t have a clue of why it’s happening.
Hope you guys experienced something similar and are able to shed some light on this! 🙂

I’ve created a new block (and a new module) to show the last entries in a certain category.
It is using the theme API plugin, and Block21 as an starting point.

For each post, I’m looking to show:
– Category
– Author name
– Entry title
– Author avatar

The first three are working perfectly, but when it comes to the author avatar the module always shows the same image, the one belonging to the user #5 (regardless of who created the post, or who is the current author).

I tried with:
– <?php echo get_avatar( get_the_author_meta(‘ID’), 55);?>
– <?php echo get_avatar( $td_author->user_email, ’55’);?>
– And a bunch of similar combinations and tricks (avatar plugins etc), but nothing seems to work.

If I do <?php echo get_the_author_meta(‘ID’);?> or <?php echo get_the_author_meta(’email’);?> it always shows the data relative to author #5, but when doing <?php echo $this->get_author();?> it shows each author’s name perfectly.

Could you give me any clue of how to solve this?
Is there a way of displaying the author’s avatar knowing just the name?

Post count: 22421

Hello,
Our theme has no implementation for user avatar. you can follow this topic to see how it can be hard-coded: https://forum.tagdiv.com/topic/author-bio-help/#post-45418
I hope this helps.
Thanks.

Post count: 10

Hi, I finally managed to get this working.

In case it helps to someone, this is the way of showing the author avatar from a custom block built through the API:

<?php echo get_avatar($this->post->post_author, 55)

(being 55 the size of the picture)

  • This reply was modified 10 years by Chucho.
Viewing 3 posts - 1 through 3 (of 3 total)
The forum ‘Newspaper’ is closed to new topics and replies.