Hi, I add profile picture field of author in node displays with this code in code field:

<?php
if (isset($object->picture)) {
  return theme('image', $object->picture);
}
?>

but, is possible add a field of my profile, "firstname" and "lastname" for example?
thanks

Comments

xtfer’s picture

Status: Active » Postponed (maintainer needs more info)

I'll need a bit more information to help you. Are you trying to get firstname and lastname from a user profile, and if so what method are you using to create user profiles?

tecnosalva’s picture

I used the Drupal core module: profile, in admin/user/profile, I've got a category named "personal" and into I add two fields: "profile_firstname" and "profile_lastname".

I have tried with this code:

<?php 
global $user;
$object= user_load(array('uid'=>$user->uid));
print $object->profile_fistname;
?>

But this print the fistname the user logged, however I want to print the author name of the node. what is wrong?
Thank you for your help.

xtfer’s picture

Status: Postponed (maintainer needs more info) » Fixed

This is not Display Suite related - you should be able to find this sort of info pretty easily by googling for it or exploring drupal.org.

global $user always returns you the current logged in user. You want to use the uid of the person who's profile you are trying to load. If you are on a page like /user/87 then you can get it using the arg function. If you are on a node, use $node->uid.

tecnosalva’s picture

I´m sorry but I am a bit clumsy programming in php, now I have tried this:

<?php 
$node_author->uid = $node->uid;
profile_load_profile($node_author);
print ($node_author->profile_firstname);
?>

but does not work.

Thanks for your help anyway

xtfer’s picture

I havent tested this, but, profile_load_profile should work with ANYTHING that contains a uid key, so try...

profile_load_profile($node);
print $node->profile->profile_firstname;
rajatgusain’s picture

@xtfer
profile_load_profile($node);
Above function will not work it needs the user object.

@tecnosalva,
Please make sure that $node is available and it contain the values of nodes.
Then use the following code :
$node_author_id = $node->uid;
$author_info = user_load($node_author_id);

Now $author_info is having all the data about the author.
if you are having the profile_firstname in the profile area then use following code to access author's firstname.

$author_info->profile_firstname;

Cheers :::::::
Rajat Gusain

xtfer’s picture

@rajat

If you read the function, you will notice that, although its signature has a $user variable, it will accept any class with a uid key.

tecnosalva’s picture

@rajatgusain @xtfer Thank you very very much for your help, now all is all right, I changed only $node for $object, would look like:

<?php 
$node_author_id = $object->uid;
$author_info = user_load($node_author_id);
print "<a href=user/".$node_author_id.">".$author_info->profile_firstname . "</a>";
?>
tecnosalva’s picture

Title: How can I add a field to author profile? » How can I add a profile field?
Status: Fixed » Closed (fixed)