Hey there. I'm trying to display information taken from the profile of the user who posted the node being viewed. I've installe dthe contemplate and prfile modules but just cannot figure it out.

To start of with a simple example I have made a field in the profile for the users real name. I tried adding the following code to my node template (which is the only thing I could think of that would work...) But nothing shows up:

<?php print $node->profile_realname ?>

Can anyone help at all?

Comments

nevets’s picture

You need to use a user object, so you need something like

<?php
$account = user_load(array('uid' => $node->uid));
print $account->profile_realname;
?>
eviljoker7075’s picture

Genius!

Thanks very much! Work's a treat!!

While I've got you here I might as well ask. I want to use this to allow my users to share ad revenue from google ads on my pages. If I provide a field in their profile to add their google adsense ID to can I use this script to call up the id from the profile and enter it into the adblock code from google?

nevets’s picture

Yes but it depends on context. Your original question was relative to a node. I am guess you have the ads in blocks so you need a way of determining which user to use for the ad. Given you have detemined that you can do what you want.

eviljoker7075’s picture

No, I am placing the ads in the node itself. I've placed my google code into the template for my nodes... will it work ok there?

nevets’s picture

Yes, that means you have code in the template that looks something like this.

print "Google Adsense Code";

So you can then do something like

<?php
$account = user_load(array('uid' => $node->uid));
$code = $account->profile_adsense_code;
// The next part depends on the details of how you print the adsense code
// IF your code is between double quotes simple replace the hardcoded code
//      with $code
// IF your code is in single quotes you will need to split the printed string at
//  at the hardcoded code and concatenate the results with $code.

// WARNING:  You should make sure $code is set before outputting the adsense code
?>