I want to use a single custom user profile field in the nodetempalte with drupal ver 5x.

<?php print $user->profile_websiteurl ?>

This doesn't work. Do I have to call mysql to make it work?

In that case, how do I make the call?

Comments

alexpott’s picture

To make your code work try:

<?php
// Access the user object
global $user;
//Load profile fields from database
profile_load_profile($user);
?>

Put this at the top of the page - then you can access profile variables. Profile_load_profile is a function in the profile module.

Alex Pott

farald’s picture

Thank you, it worked like a charm:D

farald’s picture

Worked with test-user, until I logged out:D

Problem:
I wanted to get the node author's profile info, not the currently logged-in user:)
Is there a simple way to do this?

graysadler’s picture

try this

<?php
$owner = user_load($node->uid);
?>

the $owner object is now a user object for the node's owner (author).

EDIT: the uid in $node->uid may be wrong...I'm going off of memory right now...it might be $node->owner or $node->user if $node->uid doesn't pick up the right value for the node author's user id.

Lead Developer and Founder of StreamRiot.com

farald’s picture

I tried adding this to contemplate:

<?php
$owner = user_load($node->uid);
?>

(----)

<?php print $owner->profile_mail . $owner->profile_member ;?>

It did not work, outputs nothing.
I need this for adding a js tab to articles containing various author contact information.

Any suggestions?

raponec’s picture

$owner = user_load(array('uid'=>$node->uid));

Has to be an array. Explained here:

http://drupal.org/node/46317#comment-87228

That's for pulling user info into nodes. For comments:

$owner = user_load(array('uid'=>$comment->uid));

User profile:

$owner = user_load(array('uid'=>$user->uid));

farald’s picture

Thank you so much for this, raponec, it solved 90% of my related problems! Thank you!

<?php
global $user;
$owner = user_load($node->uid); 
?>

(---)

<?php print $owner->profile_startdate;?>

The only thing not working now is a date field in the profile. It outputs "array".

Thanks again! :)

alexpott’s picture

Use print_r() to dump the array into your content with all of its elements

print_r ($owner->profile_startdate,true);

- then alter your code to print the desired element maybe something like (I don't know the array structure of the date field in the profile module)

print $owner->profile_startdate['value'];

If you have the devel module installed (which I would recommend) then you can use the dpm() command to dump variable to drupal's message system.

So for example

dpm($owner);

would dump the entire owner object - can be very useful.

Alex Pott