I think the title about sums it up.

For Drupal 7, I am specifically wanting to print the Author of the Node's Profile information. For example, if I add I biography field to my list of profile questions, I want to display this field on a node.

The core distinction here being that, I do not want to display the VISITOR'S profile information, but the AUTHOR'S information.

Thanks.

Comments

dalegrebey’s picture

Here we go... Using the user_load and passing it the User ID (Author) of the node turned out to be the trick. Copy this into your node--event.tpl.php and adjust the fields accordingly. I prefer to use a specific Content Type so that the Author Information isn't being parsed for pages that do not need to have it displayed.

  $node_author = user_load($node->uid);
  print ($node_author->roles[3]);
  print ($node_author->field_biography['und'][0]['value']);

This would for example: print the User's role (Administrator in this case) and then their Biography field.

Hope that helps.

nyoz’s picture

Hello ! Thanks for your contribution, but would $node_author = user_load($node->uid); be helpful for me to do the following :

I want to create a block containing node's and node author's informations (like the node rate, the last edit, the author name and picture, his points, etc.). But this block would be located into another region than the node content currently is attributed to (reffering to Bartik, the block would be in sidebar-second when the content is in content...).

Thks for your help !

dalegrebey’s picture

I would presume that you could use this as a starting point. Obviously the Author's Name, Picture, When the post was Created and Changed are already available to you. Regarding points and rating, I'm not entirely too sure at present.

  // Pass the Unix timestamp through Date function to format it accordingly
   print date('D, M jS Y, g:iA', $node->created);
   print date('D, M jS Y, g:iA', $node->changed);
kaztur’s picture

Hello! Great Thanks for the code, it works good!

I use this code for printing author fields in comments:

<?php $comment = $variables['comment'];
 $bizdir_titles = field_get_items('user', user_load($comment->uid), 'field_user_biz_dir'); ?>
 <div>BizDir: <?php print render($bizdir_titles[0]['value']); ?></div>

Everithing is good save the field 'field_user_biz_dir' is of type term reference and there's nothing printing on a page. Could You help me? please?

Skype: kaztur.ru
Phone: +7 917 871 09 85

dapseen’s picture

Thank you for sharing, Helpful

mittalpatel’s picture

$profile_values = profile2_load_by_user($node->uid);
$blogger_profile = $profile_values['blogger_profile'];
print $blogger_profile->field_full_name['und'][0]['safe_value'];
nvisioncurtis’s picture

Can I use this to get the real name of the blogger?

I want to replace user name with Author name ie. chutchi with Chris Hutchins,

I tried some of the above code but it failed for me :(

mittalpatel’s picture

Have you created the fields using profile2 module? What is the machine name of your profile (like in my case it's 'blogger_profile') and what's the machine name of your profile field (like in my case it's 'field_full_name')?

nvisioncurtis’s picture

Hi Mittalpatel,

Background info: I am using the blog module and Drupal 7. This is a multi-user site. profile2 module... No I have not looked into this. But I will investigate. How would this help?

I would like each post to list the authors name as if an article but the author name is not available as a variable. I also tried altering the preprocess function but that didn't work for me...

I altered the blog output with node--blog.tpl.php so that it now
some thing like

Posted: June 15, 2012 - 5:51pm
By bingham
...

but I would like to notify this so that it reads the author name

Posted: June 15, 2012 - 5:51pm
By John Bingham

However, how do I get the name of the Author?

At the very least I would like to capitalize the user name (Bingham) which I attempted to do with the PHP function ucwords() but this did not work... for some reason.

While I have your attention, I would also like to modify the link of the username to a custom author page...
I tried something like this but apparently this does not work..

node--blog--19.tpl.php (author uid)
node--blog--bingham.tpl.php

My URL alias is setup as
http://mysite.com/blog/bingham/post-title-here

Any suggestions greatly appreciated.

Curtis

mittalpatel’s picture

Hello Curtis,
I think you should check out the profile2 module as it will allow you to create more fields for the user. You can create First Name and Last Name fields and then use those values as described in my previous comment.

If you just want to make the first letter capital of the username then it can be done with CSS too. Something like

.post-info a {
    text-transform: capitalize;
}
sjhuskey’s picture

Thanks mittalpatel! That solution worked perfectly for me and ended several days of trial and error!

ballboy’s picture

Heres another way thats much easier: Enable the tokens filter module then use the following in your tpl.php:

<?php print token_replace('[node:title] Info Maintainer: <a href="../user/[node:author:uid]/contact" title="Contact [node:author]">[node:author]</a>', array('node' => $node));

Obviously this is to paste a contact link but you can use whatever tokens you like.

drupalina’s picture

Inside a view of node teasers, I'm trying to print Authors' telephone number from their profile2 field.
However, on my site only the "Business" account holders can hold a business_profile profile type.

I'm using this code:

<?php 
$profile = profile2_load_by_user($user); 
print drupal_render(field_view_field('profile2', $profile['business_profile'],'field_telephone')); 
?>

This code inside my node.tpl.php works only for those nodes that were created by "Business" account holders. For all other nodes created by normal accounts, it fills the screenwith these errors:

Notice: Trying to get property of non-object in include() (line 30 of /usr/www/users/foo/sites/all/themes/corolla/templates/node--article.tpl.php).

Can someone PLEASE help? If the user has a business_profile and if that profile has a field_telephone, it should be printed.

WorldFallz’s picture

You don't do any if-then test to see if the user has the field so when it tries to print for users that don't have the field, it throws that error.

But you say you're doing this in a view of teasers though, so why not just add a relationship to the node author and add it to the view that way?

drupalina’s picture

Thanks, I actually had to add 2 relationships: one for node author and then another one for the Profile,in order to retrieve that telephone field. It worked, but strangely not for every person who has a telephone field. My worry is that building it like this through Views is going to slower the pageloads when traffic starts pouring in. My other worry is that the view is an unordered list of teasers, which are themed from inside node--type.tpl.php, and itrequires a lot of messy CSS to put that field in the right place.

Is there a cleaner and faster way to do this from inside the node--type.tpl.php ? I mean, what would be the correct syntax for that kind of if-then test that you mentioned? Thanks.

WorldFallz’s picture

I can't say with any certainty, but I would think a single query from views would be more efficient than doing an entire profile load. Views can also be cached.

...which are themed from inside node--type.tpl.php...

That sounds really wrong. Just theme the view itself. Also, it sounds like your forcing views into formatting nodes which is not at all what views was meant to do. Although it can be used that way, there are better ways for format nodes.