Last updated August 26, 2009. Created by mike stewart on January 24, 2006.
Edited by bekasu, bryan kennedy, add1sun, Dublin Drupaller. Log in to edit this page.

Description

This describes how to override the default user list page layout when using phptemplate based themes and the profile.module.

The user list page is displayed when you click on www.example.com/profile. For an example, click through to the Drupal.org user list page.

Using this override you can control precisely which profile fields are displayed and their positioning/layout.

Step 1 of 2

In a text editor like notepad.exe, create a file called template.php using the the following snippet. If you already have a template.php file, simply add it to your existing one.

<?php
/**
* This snippet works with Drupal 4.7
* and will NOT work with Drupal 4.5 or Drupal 4.6
*/
function phptemplate_profile_listing($user, $fields = array()) {
/**
* This snippet catches the default user list pages layout
* and looks for a profile_listing.tpl.php file in the same folder
* which has the new layout.
*/
return _phptemplate_callback('profile_listing', array('user' => $user, 'fields' => $fields));
  }
?>

Upload your template.php file to your active theme folder.

Step 2 of 2

The template.php snippet catches the default user list page layout before it's displayed and looks in the same folder for a profile_listing.tpl.php file which determines the new layout.

A very simple/shortened example of a profile_listing.tpl.php file maybe illustrated as follows....(e.g. I have setup custom extended user profile fields called profile_city, profile_country, profile_postcode)....

<?php if($user->picture): ?>
<div class="picture">
<img src="/<?php print $user->picture ?>">
</div>
<?php endif; ?>
<?php profile_load_profile($user->uid) ?>
<div class="custom_profiles">
<div class="fields">Name: <?php print $user->name ?></div>
<div class="fields">City: <?php print $user->profile_city ?></div>
<div class="fields">Country: <?php print $user->profile_country ?></div>
<div class="fields">Postcode: <?php print $user->profile_postcode ?></div>
</div>

Upload your profile_listing.tpl.php file to your active theme folder and go to your user list page at www.example.com/profile to see the new layout.

For Drupal 5.x
It works the same way for Drupal 5, except for the token names used in profile_listing.tpl.php
Here is an example, with custom profile fields :

<table width = "100%" border="0" cellspacing="2" cellpadding="0" align="left">
<tr><td></td><td rowspan=5 valign= "top" align="right"><?php if($user->picture) {print '<br />'.theme('user_picture', $user);} ?></td></tr>
<tr><td>Name : <?php print check_plain($user->profile_Name) ?></td></tr>
<tr><td>Home phone number: <?php print check_plain($user->profile_home_phone) ?></td></tr>
<? if ($user->profile_prefered){ print '<tr><td> Email Address : '.$user->profile_home_email.'</td></tr>'; } ?>
<? if($user->profile_home_address){ print '<tr><td>Home address: '.check_plain($user->profile_home_address).'</td></tr>';} ?>
</table>

If also fixes the problem of the link to the user profile, it's on the picture.

You can have a look at this page : http://drupal.org/node/35728
It has been written for Drupal 5 too, it is similar to this one, and can be useful

Notes

  • Name the classes or change the layout to whatever you want.
  • Edit your style.css file or whatever your main stylesheet is called to control the the class styles.
  • You can include the user profile page snippets if you like
  • Please post tips/tricks discuss this handbook page at this thread.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.