0

In my website, users can connect, see their profiles, update their profiles and visit other users profiles

So for each users, I created a profile page user-profile.tpl.php

But I've some troubles when I'm visiting other users account.

For example in my account profile page, there is a link who's redirecting me to the edit page.

I wrote this code for showing the edit link :

<?php
  global $user;
  print l(t('Update my profile'), "user/{$GLOBALS['user']->uid}/edit");
?>

When I'm visiting a random user page, this link appears. But I want it to appear only on my profile page

And it's the same for my profile picture, when I'm visiting a random user page, my picture is always showing.

<?php 
    $user_item = user_load_by_name($user->name); // or user_load( $user->uid )
    print theme('user_picture', array('account' =>$user_item));
?>

I have no idea how to fix theses problems, that's why I need your help (I'm new to Drupal btw)

(I'm using Profile2)

Thanks

2

You can get the user id from url using arg() function. for the first part you can do something like this.

global $user;
$user_id = arg(1);
if($user->uid == $user_id) {
// means it is logged in user profile - so show edit link


}

For the second part you are loading profile of logged in user, that is why it is always showing your picture you need to do the following instead.

$user_item = user_load($user_id); // user id we got from arg()
print theme('user_picture', array('account' =>$user_item));
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.