Link to home
Start Free TrialLog in
Avatar of adrian7474
adrian7474Flag for United States of America

asked on

How to display part of an author's profile in a node

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;

Open in new window

Avatar of oliverpolden
oliverpolden
Flag of United Kingdom of Great Britain and Northern Ireland image

yes $team[0] gives you the first value.  You need to do something like

foreach ($team as $team_member) {
  $vars['field_team'] .= $team_member['value'];
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of adrian7474
adrian7474
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adrian7474

ASKER

Found my own solution.
No problem, glad you got it sorted.

Oliver - www.onlinemagnetism.com