我有一个内容类型为“项目”的网站,其中有一个领域为“项目经理”,需要一个用户。是否有一种很好的方式来显示用户在该用户个人资料中显示为该项目的项目经理的所有项目?显示用户在该用户个人资料中显示为字段的所有节点?
更新:
这是我在user_profile.tpl.php至今
...
function my_module_user_view($account, $view_mode, $langcode) {
$my_field = 'field_pm';
$uid = $account->uid; // The uid of the user being viewed.
$query = "SELECT entity_id FROM {field_data_{$my_field}} WHERE {$my_field}_target_id = :uid AND bundle='user'";
$args = array(':uid' => $uid,);
$result = db_query($query, $args);
$nids = $result->fetchCol();
if (count($nids)) {
$projects = node_load_multiple($nids); // Load all projects where that user is a PM
foreach ($projects as $project) {
$account->content['field_pm_projects'][0]['#markup'] = $project->title;
}
}
}
?>
<div class="profile"<?php print $attributes; ?>>
<?php print render($user_profile); ?>
<?php print $account->content['field_pm_projects']; ?></span>
</div>
谢谢!有效! 我只是补充说,使用“全局$用户”可以让您当前登录的用户,但分配“$ user = user_load(arg(1))”将成为当前用户配置文件的用户。 –
另外,是否有一个很好的方法来搜索多个领域(用户可能是下午或开发人员..)谢谢! –