简体   繁体   English

从user_id获取头像

[英]Get avatar from user_id

1 - I have two members witch settings are set to subscribers. 1-我有两个成员,巫婆设置已设置为订阅者。

2 - I have made a page in wordpress with the code: 2-我用以下代码在wordpress中制作了一个页面:

<img src="get_avatar" alt="Logano" onerror="this.src='./files/defaultHead.jpg'"><a>Get_name</a>
  1. Now I want get the members avatar to that img and also the name to this page. 现在,我要获取该img的成员头像以及该页面的名称。

How do I do this, what do I have to do? 我该怎么办,我该怎么办?

I've tried to find a answer but I only see this: <?php echo get_avatar( $id1, $size, $default, $alt ); ?> 我试图找到答案,但我只看到以下内容: <?php echo get_avatar( $id1, $size, $default, $alt ); ?> <?php echo get_avatar( $id1, $size, $default, $alt ); ?>

You'll need to think about PHP and HTML as 2 different languages. 您需要将PHP和HTML视为两种不同的语言。

<?php says, "we can start writing php now..." and then - ?> says "back to regular HTML" <?php说,“我们现在就可以开始编写php ...” ,然后 - ?>说“回到常规HTML”

so... <img src='' alt=''> is the html... and you want a dynamic PHP call in there... right? 所以... <img src='' alt=''>是html ...,您想在那里进行动态PHP调用...对吗?

then... <img src='<?php *stuff* ?>' alt=''> 然后... <img src='<?php *stuff* ?>' alt=''>

<?php echo get_avatar( $id1, $size, $default, $alt ); ?>

echo mean... "print out" sorta. echo意思是...“打印出来”排序。

the $things with dollar signs are just placeholders from the doc... 带有美元符号的$things只是文档中的占位符...

If you read the page, it tells you what each on is. 如果您阅读该页面,它将告诉您每个页面的含义。 You can leave out the ones you don't need. 您可以忽略不需要的内容。

you can use your user's ID's or email address I think... 您可以使用用户的ID或我认为的电子邮件地址...

<img src='<?php echo get_avatar("4") ?>' alt=''>

So, something like this should get you on your way. 因此,类似这样的操作应该可以助您一臂之力。

Scratch that... echo get_avatar spits out an image tag for you... 从头开始... echo get_avatar为您吐出一个图像标签...

wonder what happens without the echo though... ? 想知道如果没有回声会发生什么...?

So, <?php echo get_avatar("4") ?> 因此, <?php echo get_avatar("4") ?>


For the page name... it's the same idea 对于页面名称...这是相同的想法

the html would be <h2>the title</h2> html将是<h2>the title</h2>

so... <h2><?php echo get_the_title( $ID ); ?></h2> 所以... <h2><?php echo get_the_title( $ID ); ?></h2> <h2><?php echo get_the_title( $ID ); ?></h2>

You can put the page's ID in there "2" or - if it's in the loop, leave the () empty and then it will know to grab the name of that page. 您可以将页面的ID放在"2"或者-如果它在循环中,则将()留空,然后它将知道获取该页面的名称。

Person name would be something like this: 人名可能是这样的:

http://codex.wordpress.org/Function_Reference/get_userdata http://codex.wordpress.org/Function_Reference/get_userdata

<?php $user_info = get_userdata(1);
      echo $user_info->first_name . "\n";
?>

(in this case though... those $ are global variables... not placeholders. Documentation is really confusing... isn't it? ha ) (尽管在这种情况下...那些$是全局变量...不是占位符。文档确实令人困惑...不是吗?ha)

Good Luck. 祝好运。

Now when I managed to fix this I hit another one directly. 现在,当我设法解决此问题时,我直接击中了另一个。 I use buddypress and extended fields. 我使用buddypress和扩展字段。 When I look at the tag it's field_2 but I can't call it with the code above? 当我查看标签时,它是field_2,但是我不能用上面的代码来调用它吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM