• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

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

0
adrian7474
Asked:
adrian7474
  • 2
  • 2
1 Solution
 
oliverpoldenCommented:
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

0
 
adrian7474Author Commented:
Thanks, I ended putting this into my node.tpl.php file and it works great. I think with the above code I pasted before, it was an incorrect way to call the user global.




if($page){ 
   echo'  |  ';
  $node_author = user_load($node->uid);
  
  $team = $node_author->field_byline;
  if (isset($team['und'][0]['value'])) {
       print ($team['und'][0]['value']);
    }
	
   }

Open in new window

0
 
adrian7474Author Commented:
Found my own solution.
0
 
oliverpoldenCommented:
No problem, glad you got it sorted.

Oliver - www.onlinemagnetism.com
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now