为旧网站做一些维护工作。如果输入了用户的full name
,我想在其中显示它,否则,显示用户的username
。我不知道为什么下面的代码不起作用,我没有收到任何错误消息。
<?php
global $user;
$uid = user_load($user->uid);
$myprofile = 'main';
$profile = profile2_load_by_user($uid, $myprofile);
$display_name = $profile-> field_main_first_name['und'][0]['value'] &" "& $profile-> field_main_last_name['und'][0]['value'];
if(empty($display_name)){
echo $display_name = $user->uid;
}
echo $display_name
?>
答案 0 :(得分:0)
以下内容对我有用。
<?php
global $user;
$uid = user_load($user->uid);
$myprofile = 'main';
$profile = profile2_load_by_user($uid, $myprofile);
$first_name = $profile-> field_main_first_name['und'][0]['value'];
$last_name = $profile-> field_main_last_name['und'][0]['value'];
if (empty($first_name)) {
$display_name = $user->name;
} else {
$display_name = $first_name." ".$last_name;
};
?>