Creating a Basic "Biographies" Page

I used the Profile module to add a multi-line field called "Interests," and a URL field called "My Web Site or Biography Link." There are also fields for first and last names, city, state, and zip codes. There are check boxes for those who are in associated groups. This page also includes the user's picture if they loaded one.

I create a simple table (see this article). The user's web site link is a bit smaller than normal text, but includes target="_blank" so your users stay on your site.

Note that there are a lot of checks for missing data as it is like pulling teeth to get people to enter it. Also, I'm not using the t() function on the strings, because this example is for an English-only group.

<p>This page is intended to give you an introduction to the members of xxx.  The information is filled in by the members themselves in their &quot;My Account&quot; page. In order to appear on this list you must have logged in on this site at least once.</p>

<?php
echo '<div class="bios"><h3 align="center">xxx Member Biographies</h3>';
$show_blocked = FALSE;

$header = array(
  array(
'data' => t('Name')),
  array(
'data' => t('Location')),
  array(
'data' => t('Member since')),
  array(
'data' => t('Interests/Bio'))
   );
$sql = "SELECT u.uid, u.name FROM {users} u WHERE u.uid>1 ORDER BY u.name";
$sql .= tablesort_sql($header);
$result = pager_query($sql, 100);
$rows = array();

while (
$account = db_fetch_object($result)) {
 
$account = user_load(array('uid' => $account->uid));
  if (!
in_array('Members', $account->roles)) { continue; }
  if (
$account->uid > 1) {
     if (
$account->picture){$account->picture = '<img src="/'.$account->picture.'" height="100" width="100"  alt="'.$account->name.'">';}
     else {
$account->picture = '<img src="/files/pictures/bodYou.gif" height="100" width="100" border="0" alt="no picture found">';}
    if (
$account->profile_firstname) { $fullname = $account->profile_firstname . " " . $account->profile_lastname; }
    else {
$fullname = $account->name . ' ???'; }
   
$userlink = l($fullname, 'user/'. $account->uid);

    if (
$account->profile_interests) {$interests = $account->profile_interests;}
    else {
$interests = "No biography provided";}
   
$member = array();
    if (
$account->profile_hs_member) { $member[] = 'Horiticultural Society'; }
    if (
$account->profile_gc_member) { $member[] = 'Garden Club'; }
    if (
count($member) > 0) {
      
$interests .= '<br />'. "I'm a member of the ". implode(' and ', $member);
     }

    if (
$account->profile_biolink) {$interests .= '<br/><small><a href="' . $account->profile_biolink
                                          
. '" target="_blank">' . $fullname . "'s web site</a></small>";}
    if (
$account->profile_city) {$location = $account->profile_city . ", "
                                  
. $account->profile_state . " " . $account->profile_zip;}
    else {
$location = "No location provided";}
  
$status_ind = $account->status ? '': '<br/><small>Inactive</small>';
  
$x = $account->profile_date_joined['month'] . $account->profile_date_joined['day'] .                            $account->profile_date_joined['year'];

   if (
$account->profile_date_joined) {
    
$d_str = date('F Y', mktime(0, 0, 0, $account->profile_date_joined['month'],
                                       
$account->profile_date_joined['day'],
                                       
$account->profile_date_joined['year']));
   }
   else {
$d_str = '? ? ?'; }
   if (
$account->status || $show_blocked) {
    
$rows[] = array($userlink . "<br/>" . $account->picture . $status_ind,
                    
'<small>' . $location . '</small>',
                    
$d_str,
                    
$interests
                   
);
    }
/* end account_status */
 
}
}

echo
theme('table', $header, $rows) . '</div>';
?>

 

I do not understand

TheoRichel - April 2, 2008 - 13:16

Where is one supposed to paste this code?
What are the advantages of this page above adding fields to one's profile?

Thanks,

Theo Richel

paste it to a new page

clapiotte - April 18, 2008 - 12:10

just copy-paste it into a new "page" node as an admin. Use input format "php code". Then display the node with another logged in user. I personnaly changed the line
  if (!in_array('Members', $account->roles)) { continue; }
to:
  if (!in_array('authenticated user', $account->roles)) { continue; }
as I had no "Members" role by default in my fresh Drupal 5.7 install, and:
   else { $d_str = '? ? ?'; }
to
   else { $d_str =date(r,$account->created); }

have fun
laurent

 
 

Drupal is a registered trademark of Dries Buytaert.