Drupal 7, block on all profile pages. Printing fields from 'viewed user' not 'current user' -
i'm trying print few fields in block on each profile page.
the block needs display fields of user being viewed, not logged in user.
$account = user_load($node->uid); - doesn't work. user->uid doesn't either. globals user return logged in users info.
not sure how i'm supposed load block. idea?
assuming you're viewing user profile url path this
drupal/user/user_id
you can follows :
// option 1 $user = explode('/', current_path()); $user_id = end($user); // option 2 // $path = explode('/', current_path()); // $user_id = $path[count($path)-1]; $account = user_load($user_id, true); documentation current_path()
this way last part of url , pass user_load function. set true second parameter loads db , not cache.
another way same without breaking url pieces use arg() parameters
in case code
// option 3 // drupal/user/user_id // drupal = arg(0) // user = arg(1) // user_id = arg(2) $account = user_load(arg(2), true); in both cases check $user_id integer, not let pass @ least integer, can check result of user_load.
update
if using user's name in url can load full user object using user_load_by_name()
so code change little bit. try :
$account = user_load_by_name(arg(2)); i used arg simplicity, can user's name url want.
hope helps.
Comments
Post a Comment