我是PHP新手,如何从此字符串中提取电子邮件值,以通过电子邮件获取或回显用户的头像。
我已经尝试了这个并且它似乎不起作用..通过它不起作用,它显示电子邮件和默认的头像,我希望脚本使用电子邮件来获取头像。
<?php
$email = Sabai::_h($entity->getAuthor()->email);
echo get_avatar( $email, 32 );
?>
有什么建议吗?
答案 0 :(得分:0)
为什么不用简单的WordPress函数替换所有这些?
<?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?>
答案 1 :(得分:0)
实际上get_avatar()
函数在Wordpress中应用get_avatar
过滤器挂钩
return apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt);
我认为这是挂钩此过滤器的正确方法:
function mytheme_get_avatar( $avatar, $id_or_email, $size ) {
$avatar = '<img src="<' . get_template_directory_uri() . '/images/authors/' . $id_or_email . '.jpg" alt="' . get_the_author() . '" width="' . $size . 'px" height="' . $size . 'px" />';
return $avatar;
}
add_filter( 'get_avatar', 'mytheme_get_avatar', 10, 32 );
所以你也可以通过这种方式来解决你的问题。祝你好运!
答案 2 :(得分:-1)
您似乎是$email
变量中的返回对象或数组,或者它可能是空的。
确保您获得了正确的电子邮件地址,以便在 Gravatar
注册帐户时显示avatar
图片,否则会显示no-image
。
尝试在
之后输出变量 $ email$email = Sabai::_h($entity->getAuthor()->email);
var_dump($email); // To check it is array or object.
echo get_avatar( $email, 32 );