username.tpl.php - it seems broke :(

username.tpl.php - it seems broke :(

  • mouse77e's picture
  • mouse77e
  • 54
  • 2007-08-21
  • Offline
  • Tue, 05/06/2008 - 16:15

as part of my early adopter pack (tutorial 1) i seem to have username.tpl.php - it wasn't in a later download....

but it dosn't seem to be working now... any ideas?

<?php
if ($object->uid && $object->name) {
  $profilename = $object->name;
  // If the user has a full name defined, use that

  //Change the following two lines to load your fullname from wherever
  //it is stored and put it to $fullname..

$account = node_load(array('type'=>'uprofile', 'uid'=>$object->uid));
  $first_name = $account->field_first_name[0]['value'];
  $fullname = $account->field_first_name[0]['value'] . " " . $account->field_familyname[0]['value'];
  //Change - end of your modifications. $fullname should contain the name..
$username = $fullname;

if (!empty($fullname)) {
     $profilename = $fullname;
  }
  // Shorten the name when it is too long or it will break many tables.
  if (drupal_strlen($profilename) > 20) {
     $name = drupal_substr($profilename, 0, 15) .'...';
  }
  else {
     $name = $profilename;
  }
  if (user_access('access user profiles')) {
     $output = l($name, 'user/'. $object->uid, array('title' => t('View user profile.')));
  }
  else {
    $output = check_plain($name);
  }
}
else if ($object->name) {
  // Sometimes modules display content composed by people who are
  // not registered members of the site (e.g. mailing list or news
  // aggregator modules). This clause enables modules to display
  // the true author of the content.
  if ($object->homepage) {
    $output = l($object->name, $object->homepage, array('title' => t('View link')));
  }
  else {
    $output = check_plain($object->name);
  }
  $output .= ' ('. t('not verified') .')';
}
else {
  $output = variable_get('anonymous', 'Anonymous');
}

//remove the "test" string below - this is to make sure that this code
//is kicking in as needed.
//print "test: " . $output;
print $output;


I'll rephrase that...

  • mouse77e's picture
  • mouse77e
  • 54
  • 2007-08-21
  • Offline
  • Sun, 05/18/2008 - 09:04

I just re read that and i even have a time understanding it...

so...

Question: How do i display real names not user names please?


Real name

  • Michelle's picture
  • Michelle
  • 436
  • 2007-05-13
  • Offline
  • Mon, 05/19/2008 - 07:38

That wasn't part of my tutorial. Just from looking at the code you posted, I'm guessing it's overriding theme_username() and it looks like it's loading the usernode for the user and finding first/last name fields on there and using those to override the displayed name.

You could do the same thing with nodeprofile, just load that node instead. I can't get more specific off the top of my head but wanted to at least answer the post. I'm sick and traveling so not up to much support right now.

Michelle


Post new comment
The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options