Accessing and Displaying Custom Profile Fields | Drupal 6

Here are some PHP snippets to display data from custom profile fields you can set up using the core profile module in Drupal 6. In this first example I have a custom user profile field that holds the user's location with the machine-readable name of profile_location. The first block of code stores the location of the user who is logged in in the variable theLocation. The second block of code displays this value.

<?php
global $user;
profile_load_profile($user);
$theLocation = $user->{profile_location};
?>


<?php print $theLocation; ?>

Here is the PHP code that I use to display this code in a block on only the user's profile page. Put this code in the "Page specific visibility settings" with the "Show if PHP code returns true" option checked.

<?php
global $user;
if ($user->uid == arg(1) && arg(0) == 'user' && arg(2) != 'edit') {
return TRUE;
}
?>

Posted on Mon, 07/20/2009
Posted in

Comments

thank you!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.