[英]acf display image on user profile
I am really new at php , so sorry for this very basic question; 我真的是php新手,很抱歉这个非常基本的问题; i am using ACF to add a metabox to the user profile.
我正在使用ACF将metabox添加到用户个人资料。 So every user has a pic.
因此,每个用户都有一张照片。 The field is called 'badge', this is defined as an image object (but I don't know if that is correct, I just want the pic to appear on the page)
该字段称为“徽章”,它被定义为图像对象(但我不知道这是否正确,我只希望图片显示在页面上)
Then, I try to display the result on each profile page. 然后,我尝试在每个配置文件页面上显示结果。 On the documentation of acf: http://www.advancedcustomfields.com/resources/image/
关于acf的文档: http : //www.advancedcustomfields.com/resources/image/
so I tried this: 所以我尝试了这个:
<img src="<?php echo $badge['url']; ?>" alt="<?php echo $badge['alt']; ?>" />
But I am getting lost here. 但是我在这里迷路了。 I don't know how to retrieve the correct information and display it.
我不知道如何检索正确的信息并显示它。
Could someone please help? 有人可以帮忙吗?
Many thanks, and sorry again for this very basic question i guess! 非常感谢,对于这个非常基本的问题,我再次表示抱歉!
Sonia 索尼娅
It's been a while since the question has been asked, but here's a working code exemple of what you can do to retreive the Badge custom field on the current logged user: 提出问题已经有一段时间了,但这是一个有效的代码示例,它可以用来检索当前登录用户的Badge自定义字段:
<?php
$user = "user_".$user_ID;
$badge = get_field('avatar', $user);
?>
<img src="<?php echo $badge['url']; ?>" alt="<?php echo $badge['alt']; ?>" />
Hope it will help for the future! 希望对将来有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.