In a recent support request, someone asked how to display the user's points below the user picture (avatar).

This article answers this question.

First, in your theme directory, find the file called template.php. If one does not exist, create it, and make sure it starts with the <?php tag.

Then add this function in it.

Go to the setting, and enable user pictures.

Now, below each user's picture, there should be the number of points that this user has earned so far.

function phptemplate_user_picture($account) {
if (variable_get('user_pictures', 0)) {
if ($account->picture && file_exists($account->picture)) {
$picture = file_create_url($account->picture);
}
else if (variable_get('user_picture_default', '')) {
$picture = variable_get('user_picture_default', '');
}

if (isset($picture)) {
$alt = t("@user's picture", array('@user' => $account->name ?
$account->name : variable_get('anonymous', t('Anonymous'))));
$picture = theme('image', $picture, $alt, $alt, '', FALSE);
if (!empty($account->uid) && user_access('access user profiles')) {
$picture = l($picture, "user/$account->uid",
array('title' => t('View user profile.')), NULL, NULL, FALSE, TRUE);
$picture .= "<div>" .
userpoints_get_current_points($account->uid) . "</div>";
}

return "<div class=\"picture\">$picture</div>";
}
}
}

And there you have it.

 

Comments

Fri, 2009/02/27 - 17:34

This code doesn't seem to work for me.
I even added the code in template.php

Why is it not working?

Is your Drupal or Backdrop CMS site slow?
Is it suffering from server resources shortages?
Is it experiencing outages?
Contact us for Drupal or Backdrop CMS Performance Optimization and Tuning Consulting