Hello,

I just launched a site with an in-depth registration form. I have used various categories with number prefixes (1 Personal Information, 2 Home Address) etc. However when I click to view a user, all of the information is out of order - beginning with categories 7-9, then 1, then 6, and so on.

I just want all the information to be displayed in order! I tried making a custom user_profile.tpl.php (and editing template.php to redirect to the custom user_profile.tpl.php) but it isn't doing anything. Plus, I don't really need a custom layout (only the user and administrators can view the profiles). I just need the categories to be in order, and I looked into using php sort, but I don't think that's the right function or at least I'm not using it properly.

Can someone give me a quick fix to sort $category 0-9 (or 1-9, really)? Thanks!

Comments

nationalwind’s picture

To clarify, everything shows up in order on Admin > User Management > Profiles and also when users registers.

it is just the post-registration output at www.mysite.com/user/12 that is out of order.

BluesmanEP’s picture

I've got my profile categories named with numbers at the beginning, but in the user profile view (www.mysite.com/user) the categories display out of order. They display correctly in the profile admin page, just not when displaying a user's information.

Help!

Thanks.

NicoDruif’s picture

Any ideas on this subject yet? How can we order categories on a profile page...?

www.druifdesign.nl

NicoDruif’s picture

I did manage to sort the profile categories by calling them in a certain order in my user-profile.tpl.php like this:

		<?php print $profile['Echte naam']; ?>
		<?php print $profile['Contact']; ?>
		<?php print $profile['Adres']; ?>
		<?php print $profile['summary']; ?>
		<?php print $profile['vcard']; ?>

www.druifdesign.nl

Peter Swietoslawski’s picture

I've got the same problem. There is one missing sorting which fixes everything.

If you go to /modules/user/user.pages.inc find template_preprocess_user_profile function and right before line

$variables['user_profile'] = implode($variables['profile']);

add code to sort array by keys

ksort($variables['profile']);

Now before user profile will be concatenated to a string the array keeping all the fields for user profile will be sorted by categories (keys in $variables['profile'] array are user's profile categories).

Note
This sorting is a string sorting the same as used on /admin/user/profile page. Just for consistency. This means that if you name your categories starting with numbers for instance "12. My category", this will be placed before "2. My category".
But don't think anyone will go so wild as to have more than 9 categories.

WorldFallz’s picture

Just as an fyi-- the better way to do this would be to override the template_preprocess_user_profile function (that's the entire purpose of the template functions) in your theme's template.php file. Modifying core files essentially creates a fork that you must update and maintain yourself. Maybe not a big deal for a handful of sites, but gets old fast with anything more than that.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

Peter Swietoslawski’s picture

Very good point.

And some tweak. I've just realized that the picture will be rendered at the bottom. To fix this the function should look like this:

function template_preprocess_user_profile(&$variables) {
  $variables['profile'] = array();
  
  // Sort sections by weight
  uasort($variables['account']->content, 'element_sort');
  
  // Provide keyed variables so themers can print each section independantly.
  $user_picture = '';
  
  foreach (element_children($variables['account']->content) as $key) {
    if ($key == 'user_picture') {
        $user_picture  = drupal_render($variables['account']->content[$key]);
        continue;
    }
	
    $variables['profile'][$key] = drupal_render($variables['account']->content[$key]);
  }
  
  ksort($variables['profile']);

  // Collect all profiles to make it easier to print all items at once.
  $variables['user_profile'] = $user_picture . implode($variables['profile']);
}
Peter Swietoslawski’s picture

Using Drupal 6 I can't override template_preprocess_user_profile function by placing it in template.php under template folder (currently I'm using Garland as a theme but tried this for Bluemarine as well).

If I leave the function with unchanged name of course Drupal crashes as it gets name conflicts which means that it scans the template.php file.

I've tried to rename the function to sth like garland_preprocess_user_profile, phptemplate_preprocess_user_profile but Drupal completely ignores renamed function.

Any ideas?

WorldFallz’s picture

garland_ and phptemplate_ should both work-- did you clear the theme registry?

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

Peter Swietoslawski’s picture

Here are my steps:

  • I've placed the override function as garland_preprocess_user_profile under /themes/garland/template.php.
  • I've cleared cache with /devel/cache/clear?destination=user%2F1 and emptied site cache under /admin/settings/performance (anyway I had caching disabled).
  • I've emptied cache from my browser, restart, log into the site....and still nothing.

However if I place ovverride function in template.php for let's say breadcrumbs named like garland_breadcrumb it does work!

I've run the site through Eclipse PDT debbug mode with breakpoint in my overriden garland_preprocess_user_profile function and it turned out that it's never reaches the code.

If I use devel Themer info and highlight profile box this is the info I'm getting:

Template called:
user-profile.tpl.php
File used:
modules/user/user-profile.tpl.php
Candidate template files:
user-profile.tpl.php
Preprocess functions:
template_preprocess + template_preprocess_user_profile

Which just confirms my finding with Eclipse. I'm puzzled. Is there sth I'm missing?

BTW
I've tried this in Drupal5 overrrding in Garland's template.php and it works like a charm.

WorldFallz’s picture

hmmm... what happens if you try phptemplate_preprocess_user_profile in another theme?

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

Peter Swietoslawski’s picture

I've tried Blumarine and the same story. I can override template_breadcrumb with sth like phptemplate_breadcrumb but phptemplate_preprocess_user_profile is completely ignored?!

Isn't it like this that "preprocess" functions need some different approach?

BTW I've tried to use Pushbutton theme and I'm not even able to override template_breadcrumb??? What happens is that template.php is not even read (you need to create one as this theme doesn't provide one). So I've created the file and put there template_breadcrumb function and PHP dind't complaine of name duplicate!

valeriod’s picture

You need to copy modules/user/user-profile.tpl.php in your template directory.

ciancomp’s picture

I am new to drupal and have been very impressed so far unlike other CMS Ive used things work and act as expected. This has been the only real issue I have discovered. I am glad to see there is a knowledgeable user group as well.

gagarine’s picture

I test the solution http://drupal.org/node/270352#comment-1064216

- I create function phptemplate_preprocess_user_profile(&$variables) { in my template.php files in my theme
- I add the user-profiles.tpl.php files in my theme
- clear cache...

But after that the user page is empty. The page are displaying but without content inside after the title.

If i add an "echo $variables['user_profile']" at the end of the phptemplate_preprocess_user_profile(&$variables) function they have nothing inside...

https://interface-network.com - Interface Network is an action and research technology governance agency.

ohgila_linuxnewbie’s picture

problem solve!

saitostroitel’s picture

/modules/user/user.pages.inc

right before line
$variables['user_profile'] = implode($variables['profile']);

add code to sort array by keys
ksort($variables['profile']);

- Thanks!!! It really works!

mikespainhower’s picture

The following module provides a solution:
http://drupal.org/project/profile_category_weight

izmeez’s picture

I realize this thread spans posts from several years.

I am trying to resolve the problem with the user profile view page in Drupal 6.x where the categories are not in order.

The profile_category_weight module only applies to the tab menu and not the profile view page itself.

The idea of an override in the template.php file sounds like the proper solution but does not work.

The only solution appears to be a hack to core modules/user/user.pages.inc to add the ksort line.

Unfortunately this also places the user picture at the bottom.

Can anyone suggest a better solution? Thanks.

izmeez’s picture

In case anyone else is interested, I have found that copying user-profile.tpl.php to the theme directory and editing it with the following seems to work:

<div class="profile">
  <?php print $profile['user_picture']; ?>
  <?php print $profile['Contact Information']; ?>
  <?php print $profile['More Information']; ?>
  <?php print $profile['Terms Of Use']; ?>
  <?php print $profile['summary']; ?>
</div>

I'm still not sure if this is the best way but at least it avoids hacking core.