Drupal:如何在节点中显示作者个人资料的一部分
除了个人资料页面之外,我一直在尝试显示在节点的用户帐户的管理字段部分中创建的自定义字段。我对这段代码遇到的问题是,它将显示它找到的第一个字段,并为每个用户显示该字段,而不是该特定用户的字段。 和想法?我相信它正在查找数组中的第一个值,而不是数组中特定用户的值。
这是到目前为止的设置: 将其添加到我的主题的 template.php 中:
function mythemename_preprocess_node(&$vars) {
global $user;
$user = user_load($user->uid); // Make sure the user object is fully loaded
$team = field_get_items('user', $user, 'field_team');
if ($team) {
$vars['field_team'] = $team[0]['value'];
}
}
然后,将其添加到我的 node.tpl.php 中,以便在节点上显示它。
if (isset($field_team) && !empty($field_team)) :
echo '$field_team.'</div>';
endif;
更新: 在这里找到我自己的答案: http://drupal.org/node/1194506
使用的代码:
<?php
$node_author = user_load($node->uid);
print ($node_author->roles[3]);
print ($node_author->field_biography['und'][0]['value']);
?>
I have been trying to do display a custom field I created in the manage fields section of user accounts for nodes in addition to the profile page. The problem I am having with this code is that it will display the first field it finds and display that for every user, not the field for that particular user.
And ideas? I believe it's finding the first value in the array and not the value for the particular user in the array.
Here is m setup so far:
Added this to my template.php of my theme:
function mythemename_preprocess_node(&$vars) {
global $user;
$user = user_load($user->uid); // Make sure the user object is fully loaded
$team = field_get_items('user', $user, 'field_team');
if ($team) {
$vars['field_team'] = $team[0]['value'];
}
}
Then, added this to my node.tpl.php in order to display it on nodes.
if (isset($field_team) && !empty($field_team)) :
echo '$field_team.'</div>';
endif;
UPDATE:
Found my own aswer here:
http://drupal.org/node/1194506
Code used:
<?php
$node_author = user_load($node->uid);
print ($node_author->roles[3]);
print ($node_author->field_biography['und'][0]['value']);
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 drupal 的“作者窗格”模块来实现此目的。试试这个:
http://drupal.org/project/author_pane
You can use drupal's 'Author Pane' module for that. Try this:
http://drupal.org/project/author_pane