2

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']);
?>
kidA
  • 35
  • 5
  • Not sure I fully understood your intention, but the `global $user;` variable refers to the user doing the request (either a logged in known user, or the anonymous user), _not_ to the node author. For that, you'd need to do a `user_load($vars['node']->uid)`. – Henrik Opel Dec 09 '11 at 15:49
  • You should turn your Update findings into an answer to your own question, and later on accept it, so that the question does not stay open as 'unanswered'. – Henrik Opel Dec 09 '11 at 15:53
  • Henrik, thanks. New to the exchange here, I tried and it said I had to wait 8 hrs, so I updated the question for others to see. I guess I can come back in 8 hrs and answer. – kidA Dec 09 '11 at 15:59
  • @kidA: I see - sorry to ask for stuff you already tried. I did not know about the current timing constraints for 'self answering' :/ – Henrik Opel Dec 09 '11 at 20:27

1 Answers1

2

You can use drupal's 'Author Pane' module for that. Try this:

http://drupal.org/project/author_pane

ARUN
  • 350
  • 1
  • 9
  • 30