我有一个内容类型为“项目”的网站,其中有一个“项目经理”字段,用于接收用户。有没有一种好方法可以显示用户在该用户的个人资料上显示为该项目的项目经理的所有项目?
更新:
这是我到目前为止在 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>