Drupal:如何在节点中显示作者个人资料的一部分

发布于 2024-12-20 13:25:14 字数 984 浏览 6 评论 0原文

除了个人资料页面之外,我一直在尝试显示在节点的用户帐户的管理字段部分中创建的自定义字段。我对这段代码遇到的问题是,它将显示它找到的第一个字段,并为每个用户显示该字段,而不是该特定用户的字段。 和想法?我相信它正在查找数组中的第一个值,而不是数组中特定用户的值。

这是到目前为止的设置: 将其添加到我的主题的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯 2024-12-27 13:25:14

您可以使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文