3

How does one display a custom field from a user's profile in comment.tpl.php?

1 Answer 1

2

The comment.tpl.php template file receive a $comment value, which contains the comment object. Between its properties, there is $comment->uid, which can be used to get the user object for the author of the comment, with user_load($comment->uid). If you are instead interested in the author of the node containing the comment, then you can use the following code.

$node = node_load($comment->nid); $uid = $node->uid; if ($uid) { $user = user_load($uid); } 

In both the cases, the code should be used in the preprocess function, not in the template file used for the comments. In this case, $variables['comment']->uid, and $variables['comment']->nid are instead used.

2
  • Thank you! I have just one question. How do i show term refference field? Thank you! Commented Feb 4, 2013 at 22:20
  • That is a different question. :) There is probably a question about that already. Commented Feb 4, 2013 at 22:23

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.