我想显示当前登录用户的gravatar,如果用户没有gravatar,它将显示默认的wp man(或使用URL的img)
这是我目前的代码;
<div class="gravatar">
<img src="http://techyoucation.com/wp-content/themes/blank/images/treehouse.png" alt=""/>
</div>
上面的代码只显示了一个随机图片,我想将其更改为已登录用户的图片(当没有用户登录时,它会隐藏但我会在以后发生这种情况。)
所以有人知道我需要做些什么才能让它发挥作用吗?
提前致谢
Aled
更新
使用
<div class="logo"><a href="http://techyoucation.com"><img src="<?php
$user_id = get_current_user_id() // Get the user ID
$size_avatar = 50 // Set the avatar size
$default_avatar = 'http://techyoucation.com/wp- content/themes/blank/images/treehouse.png' // Set your default image url
echo get_avatar( $user_id, $size_avatar, $default_avatar );
?>" alt="techyoucation logo" width="219" height="47" id="Logo" /></a></a>
Dreamweaver说有3个语法错误?我的代码错了吗?
由于
更新
好的,现在我有了;
<div class="gravatar">
<img src="<?php
$user_id = get_current_user_id(); // Get the user ID
$size_avatar = 50; // Set the avatar size
$default_avatar = 'http://techyoucation.com/wp-content/themes/blank/images/treehouse.png'; // Set your default image url
echo get_avatar( $user_id, $size_avatar, $default_avatar );
?>" alt=""/>
</div>
但图片并未显示。当我右键单击并选择复制图像URL时,它会给我 &#34; http://techyoucation.com/%3Cimg%20alt=&#39;&#39;%20src =&#39; http://0.gravatar.com/avatar/?d=http://techyoucation.com/wp-content/themes/blank/images/treehouse.png&s=50&#39;%20class =&#39;化身%20avatar-50%20photo%20avatar-默认&#39;%20height =&#39; 50&#39;%20width =&#39; 50&#39;%20 /%3E&#34;
任何想法。
由于
答案 0 :(得分:0)
您只需使用由wordpress可插入函数get avatar提供的功能:
<div class="gravatar">
<?php
$user_id = get_current_user_id(); // Get the user ID
$size_avatar = 50; // Set the avatar size
$default_avatar = 'http://techyoucation.com/wp-content/themes/blank/images/treehouse.png'; // Set your default image url
echo get_avatar( $user_id, $size_avatar, $default_avatar ); // This prints the <img> tag with correct avatar image url
?>
</div>