How does one display a custom field from a user's profile in comment.tpl.php?
1 Answer
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.
- Thank you! I have just one question. How do i show term refference field? Thank you!Dzoni– Dzoni2013-02-04 22:20:20 +00:00Commented Feb 4, 2013 at 22:20
- That is a different question.
:)There is probably a question about that already.2013-02-04 22:23:41 +00:00Commented Feb 4, 2013 at 22:23