我正在尝试显示acf中的用户信息。如果我使用以下内容,则会显示普通文本、收音机、选择和日期字段:
<?php $current_user = wp_get_current_user(); echo $current_user->user_gender; ?>
我已经创建了2个图像自定义字段,每个字段我都想用作头像。如果自定义字段名为user\\u banner和user\\u avatar,我如何获取要显示的图像。
这些字段是来自acf的自定义字段,分别是user\\u banner和user\\u avatar。
以下是页面模板的完整代码:
<?php
/**
Template Name: View Profile
*/
get_header();?>
<section class="page-profile">
<div class="container-fluid">
<div class="row">
<div class="col-sm-4">
<div class="profile-user-info">
<div class="profile-info-row">
<div class="profile-info-name"> Username </div>
<div class="profile-info-value">
<span><?php $current_user = wp_get_current_user(); echo $current_user->user_login; ?></span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> First Name </div>
<div class="profile-info-value">
<span><?php $current_user = wp_get_current_user(); echo $current_user->user_firstname; ?></span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Last Name </div>
<div class="profile-info-value">
<span><?php $current_user = wp_get_current_user(); echo $current_user->user_lastname; ?></span>
</div>
</div>
<div class="hr hr-8 dotted"></div>
<div class="profile-info-row">
<div class="profile-info-name"> Email </div>
<div class="profile-info-value">
<a href="mailto:<?php $current_user = wp_get_current_user(); echo $current_user->user_email; ?>"><?php $current_user = wp_get_current_user(); echo $current_user->user_email; ?></a>
</div>
</div>
<div class="hr hr-8 dotted"></div>
<div class="profile-info-row">
<div class="profile-info-name"> Gender </div>
<div class="profile-info-value">
<span><?php $current_user = wp_get_current_user(); echo $current_user->user_gender; ?></span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Age </div>
<div class="profile-info-value">
<span><?php $current_user = wp_get_current_user(); echo $current_user->user_birthday; ?></span>
</div>
</div>
<div class="profile-info-row">
<div class="profile-info-name"> Country</div>
<div class="profile-info-value">
<span><?php $current_user = wp_get_current_user(); echo $current_user->user_country; ?></span>
</div>
</div>
</div>
<?php
$imgurl = get_field(\'user_banner\',$user->ID);
if (filter_var($imgurl, FILTER_VALIDATE_URL) === FALSE)
{
$imgurl = wp_get_attachment_url($imgurl);
}
echo \'<img src="\' . $imgurl . \'" alt="image">\';
?>
<?php
$imgurl = get_field(\'user_avatar\',$user->ID);
if (filter_var($imgurl, FILTER_VALIDATE_URL) === FALSE)
{
$imgurl = wp_get_attachment_url($imgurl);
}
echo \'<img src="\' . $imgurl . \'" alt="image">\';
?>
</div>
</div>
</div>
</section>
<?php get_footer(); ?>
我在某处找到了所用图像的代码,但当我检查时,它显示如下:
请帮忙,谢谢。