By juicestain on
Hey there,
Anyone know how to pull the avatar of a user as you are looking at their profile, but in a block? I'm not a PHP wiz at all, and I've only figured out a way to print the logged in users picture. Here's the code I have at the moment. Please disregard the sloppiness; the first part is the unfunctional part. Would a db_query be what I need?
<?php global $user; ?>
<?php if (arg(0) == 'user' && $user->uid != arg(1)) : ?>
<div class="userpic2"><?php print theme('user_picture', $user->uid); ?></div>
<?php elseif ($user->uid) : ?>
<div class="userpic"><?php print theme('user_picture', $user); ?></div>
<?php else : ?>
<div class="userpic2"><img src="http://tenning.com/themes/box_grey/noaccount.png" /></div>
<?php endif; ?>
Thanks in advance!
Comments
Hi,
Hi,
I think you are trying to do something silimar to this:
http://www.themes4urmobilephone.com/user/dakku
http://www.themes4urmobilephone.com/user/admin
Although I am not displaying the image in a block, but that is farily easy to do anyway. Here is how I would go about doing what you need:
Route 1: (harder, but more flexible)
1) write your own module that can generate a block, see the handbook on code to generate a block from inside of a module.
2) Use the hook_user to add avatar image code to the user
3) add your costom code to the block above
Route 2: (easy)
1) Alternatively, create a block using drupal's admin/build/block/add
2) Copy paste the code into your block:
3) enable the block on "user/*" pages.
Post here if you need more help
Route 2
Sorry, I'll be a bit more clear. I wrote my plea late last night.
Basically I want to have your avatar when you're logged in the upper right corner of the page. However, I want this to change to display the avatar of a different user when you are viewing their profile.
The code works except for
which does not return the avatar of another user when on their profile.
ahhh..
ahhh..
you see $user is the object for the user that is logged in (ie YOU). If you need to display the avatar per user profile you need to do something like:
The above assumes that you are not using pathauto to alias the user profiles. if you are you will need to do a lookup on the alias table to get to the uid firstly!!
Let me know if you need more help.
great, so you've pinpointed
great, so you've pinpointed my problem now.
i am using pathauto to alias the user profile. sorry for all the trouble, but could you point me to how to grab the uid from the generated alias? thank you!
i think the solution lies a
i think the solution lies a line of code that is able to extract/load a user from the uid supplied in arg(1). i wish my php skills were better...
hiya again, if you are using
hiya again,
if you are using path auto, here is the complete code you will need
good luck
thanks for the help
i couldn't get your code to work, but i did manage to get it working with the following code for anyone who may be interested:
thanks for the suggestions..
Thank you
This was exactly what I was looking for.
- Much Appreciated
I am trying to do this exact
I am trying to do this exact same thing, but your code isn't working for me. It always displays the default avatar (as if the user hasn't uploaded their own) .. no matter what.
Is there something that I need to tweak with the above code so that it works with my version of Drupal (5.6) ?
Seems like it only works for
Seems like it only works if you're logged in as an admin.
Just put in u.picture in to the code and it will work for all users.
Help
Where is the u.picture supposed to go?
After u.name like this:
After u.name like this: $result = db_query("SELECT u.uid, u.name, u.picture
Thanks
Sorry Chippe, that was obvious
Thanks for your help.
Bookmarking, greetings,
Bookmarking, greetings, Martijn
How would I alter this to
How would I alter this to display the $account's picture of the user profile being displayed. Can't figure it out....
For the ones who google this
For the ones who google this thread, or for you if you didn't find the solution yet:
The best way is to use user_load. This way you don't have to deal with the query. Assuming the path is something like ?q=user/%
Is it possible to implement imageCache profiles to this code?
Is it possible to implement imageCache profiles to this code?
I think this one works the
I think this one works the best. Thanks dalad.
It BASICALLY works for me,
It BASICALLY works for me, dalad, but I get this error:
warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /var/www/websites/drupal6/sites/all/modules/imagecache_profiles/imagecache_profiles.module on line 41.
Any ideas, anyone?
im using $owner =
im using
$owner = user_load(arg(1));
print theme('user_picture', $owner);
in a block using php input filter. Does not seem to work. Has anyone got this to work? Im trying to display the picture of the user who's profile is being viewed in a block.
thanks
I think the previous code is
I think the previous code is deprecated. Declare the global variable $user which will get drupal's global user (currently logged in), then call print theme(...:
This will print the user's pic/avatar