开发者

How can I display user avatar by knowing user ID(uid) in Drupal?

开发者 https://www.devze.com 2023-03-20 18:19 出处:网络
I want to display user picture if the user id开发者_如何学Python is known. Is possible to do it without using additional modules?If you know the user id you want to get the picture of you can use user

I want to display user picture if the user id开发者_如何学Python is known. Is possible to do it without using additional modules?


If you know the user id you want to get the picture of you can use user_load(). user_load() will load a user object full of a user's information. To find the structure of the user object, you can use print_r().

Example for Drupal 6:

<?php
  $account = user_load(10);
  print theme('image', $account->picture, 'User Avatar', $account->name . "'s Avatar");
?>

There is also more you can do with theme_image(), like adding attributes to the img tag, etc.

If you are looking for the picture of the currently logged in user, you don't even need to use user_load() or the uid, simply do the following:

<?php
  global $user;
  print theme('image', $user->picture, 'User Avatar', $user->name . "'s Avatar");
?>

These examples were for Drupal 6 (since no version was specified) but there are only slight changes for Drupal 7.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号