Load User Profile Items in Node : Drupal

Drupal is so robust that you can do almost anything. However, they will be a time when you will have to do some programming to achieve your goal. For instance, loading user profile into node. In general to load author’s profile item into node. By default, node saves only author’s username into every post. Sometimes, you will want to display author’s Full Name instead of username. It does make better sense, doesn’t it?

Here goes… in node.tpl.php or any custom node.tpl.php, insert this code:

$node_author->uid = $node->uid;

This function will call upon the profile items of the author and then load it up for your perusal. You can then call any fields of the profile items to be displayed in your nodes. For example, you may want to load the Full Name and Work Designation of the author in your node. As shown here:

print t('<span class="date_post">Posted on ') . 
format_date($node->created, 'custom', "d F Y") . ' by ' . ucwords(strtolower($node_author->profile_name)) . ' ' .
'(' . ucwords(strtolower($node_author->profile_designation)) . ')' .

As you can see here, instead of calling node->name which is the username and the only available information of the author by default, you can now call any profile items of the author. The profile_load_profile function has loaded the author’s information and you may call any of the profile items available.

Before using the profile_load_profile to call author’s profile item


After loading author’s profile items into node usng profile_load_profile


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.