Thought it best to start a discussion re: overriding the USER LIST page layouts here, rather than in the handbook.

In response to a question by Steve:

-----------------------------------------------
I used your snippet to display profile. It works fine when I display it in http://www.mysite.com/user/John_Smith. All the profile fields have their label and looks exactly what I wanted. I will look like:

Name: John Smith
City: New York
About me: I am a web designer.

But when I display it as http://www.mysite.com/profile or http://www.mysite.com/profile/city/new_york to list all the profiles, then it does not show the 'profile field labels' and only profile fields are listed . It looks like:

John Smith
New York
I am a web designer
----------------------------------------------

Hi Steve,

I haven't created an override for the user_list pages yet, so I don't have a quick answer to your query.

I think you need to override the theme_user_list function. the example above overrides the theme_user_profile function.

I don't have time to try this at the moment, but, if you try this:

  1. copy the override snippet for the user_profile and add it to your template.php file
  2. before saving the new template.php file, change "user_profile" to be "user_list" eg. instead of phptemplate_user_profile it should read phptemplate_user_list. (do the same for the phptemplate callback)
  3. save you're new template.php file and upload it to your active theme folder
  4. create a user_list.tpl.php file and play around with how your fields are displayed

I hope that makes sense. I don't have time at the mo to try that out, but give it a lash. (make a backup of you're current template.php file first, so you can revert back if you run into difficulties).

Post back up here and I'll try and answer any questions as they pop up.

Dub

Comments

wilgrace’s picture

Thanks for starting this up Dub - exactly what I'm after. I got to the solution you offered after trying a bunch of stuff on theming the profile list page, but am having no joy.

Your solution makes sense, but it doesnt seem to be calling the user_list file - I wonder if that's the right theme override? I've been trying to find what it might be called, but no joy so far. Will keep going and post it up if I find it.

It'd be really good to get a final solution for themeing the profile lists - for me and I bet a lot of others, this will be a fairly big and important part of the site.

Thanks again Dub

Dublin Drupaller’s picture

Hi Wilgrace..

Sorry, you were right..it was the wrong function I was calling, it should have been profile_profile instead of user_list..here is a working version (tested on Drupal 4.6)

Item #1 - Template.php file snippet:

global $user;
if($user->uid) // check to see if the user is logged in
{
function phptemplate_profile_profile($user, $fields = array()) {
  // Pass to phptemplate, including translating the parameters to an associative array. The element names are the names that the variables
  // will be assigned within your template.
  /* potential need for other code to extract field info */
return _phptemplate_callback('profile_profile', array('user' => $user, 'fields' => $fields));
  }
}

Item #2 - create a profile_profile.tpl.php file and order the fields however you want (in the same way as the user_profile.tpl.php file works) and with whatever line breaks or prefixes you want..

Hope that helps someone. I've just tested it and it works perfectly. This offers total control on how your USER LIST pages look.

Dub

EDITED: As an afterthought user_list may have worked if i didn't have the profile.module enabled. If you get a chance to try that, can you let me know if that's the case? I think this will make a very useful handbook page, but it would be worth testing a bit more first.

Also, I'm wondering if only the fields you have specified or are all the profile fields available. Can you test that as well?

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

steve22’s picture

Hi dub,
thanks you so much. It works perfectly!

I tested in Drupal 4.6. It works without hitch.

Thanks again.

steve

Dublin Drupaller’s picture

No worries Steve. Glad to be of help.

I have created a handbook page called Example: theming the user list pages for others which links back here for discussions.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

wilgrace’s picture

Yeah, nice one Dub - this looks like a fairly significant themeing issue you've cracked.

It also looks like you can call just about any field, and editing the layout is really easy - I've got it looking exactly as I want it.

thanks again, i hope enough people find this thread when trying to do the same.

steve22’s picture

Yes, this is a great work by dub. thanks again!

I have one other question. When I display the profiles of users living in 'New York' city using http://www.mysite.com/profile/city/new_york, how can I display the title 'New York' city for the profile page?

I presume for this to work I have to insert drupal_set_title(t('$user->profile_city')) or something like that in template.php or may be in the profile.module file. But with my elementary knowledge of php, i can't make it work.

Dublin Drupaller’s picture

try this..

  1. go to ADMINISTER -> SETTINGS ->PROFILES
  2. click on the EDIT link to edit the CITY field
  3. at the very bottom, type in a page title..something like "Users from the city of %value.."

You may need to insert that into your profile_profile.tpl.php file..not sure if page.tpl.php will automatically pick that up for you.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

steve22’s picture

It works! Without modifying anything in profile_profile.tpl.php.

Thanks again dub!

dpw’s picture

Hi All,

Thanks Dub for all of your work in this area... very helpful! I have successfully themed profile_profile and I am wondering how I can stipulate the order of the users appearing in the list.

For example, if each user is associated with a department, ideally I would want the department heading and then the users listed alphabetically under their respective department. (I think the current order is last modification date).

I'm not sure this is a theming issues since the function call seems to pass only one user at a time, so the order has been determined before the theme modifications are made.

Any suggestions?
dpw

ryanrain’s picture

famo’s picture

hii there :)

i followed the steps of costomizing the users list.. i'm using spreadfirefox phptemplate based theme now... and though the users list are vewing, the list doesn't make sense...

it shows like this..
note: here are three users in my test site, which are admin, Fareh M, famo

Name: Admin
City: Kuwait
Country: Kuwait
Name: Fareh M
City:
Country: 0
Name: famo
City:
Country: 0

they are displayed like this without no breaking lines... :S

how to come over this and display the list probably?
how to make the users list looks like the one in drupal.org/profile ..?

Dublin Drupaller’s picture

Hi Famo..

Do this:

  1. go to your active theme folder
  2. delete the template.php file
  3. delete the profile_profile.tpl.php file
  4. go to your www.example.com/profile page and click refresh

Hpoe that helps

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

famo’s picture

Dear dublin, i dont want to delete the files coz they are great enough and working with me and i know i can delete them at any time, but is there any other way to make the users lists look even better?

Dublin Drupaller’s picture

Hi Famo...

Have a look at this page which is about Customising the user profile nodes(a "before" and "after" example with screenshots).

Using a similar approach, you can add styles to your profile_profile.tpl.php file...for example:

<div class="profile">
<div class="field">USERNAME: <?php print $user->name ;?></div>
 <div class="field">CITY: <?php print $user->profile_city ;?></div>
 <div class="field">Country: <?php print $user->profile_country ;?></div>

And in your style.css file edit the classes to put a box around each user list..

.node #profile .profile {
  width: 100%;
  border: 1px solid #eaeaea;
  margin-bottom: 1em;
  _position: relative; /* avoid IE peekaboo bug */
}

the above style snippet will put a 1px border around each users profile on the user list page.

A good resource for CSS is http://www.cssplay.co.uk
Some of the examples up there are great.

Hope that makes sense..

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

famo’s picture

dub i did exactely what u told me and i even made the a border a 3px border but it's still the same as it was before, nothing is change at all..

Name: Admin
City: Kuwait
Country: Kuwait
Name: Fareh M
City:
Country: 0
Name: famo
City:
Country: 0

Dublin Drupaller’s picture

can you paste your profile_profile.tpl.php code up here?

Just paste it in a comment and type in

(open Angle bracket)code(close angle bracket)

Your profile_profile.tpl.php code here

(open Angle bracket)/code(close angle bracket)

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

famo’s picture

<?php if($user->picture): ?>
<div class="picture">
<img src="/ <?php print $user->picture ?> ">
</div>
<?php endif; ?>
<div class="profiles">
<div class="fields">Name: <?php print $user->name ?> </div>
<div class="fields">City: <?php print $user->profile5_ ?> </div>
<div class="fields">Country: <?php print $user->profile4_ ?> </div>
</div>
Dublin Drupaller’s picture

looks good...

try renaming "profiles" to "profile" and it might pick up the default Drupal css.

unless you have already defined your "Profiles" styles.

Also put the <div class="profiles"> line above the user picture snippet. So the whole profile goes into the box.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

famo’s picture

now the code is

<?php if($user->picture): ?>
<div class="profile">
<div class="picture">
<img src="/ <?php print $user->picture ?> ">
</div>
<?php endif; ?>
<div class="fields">Name: <?php print $user->name ?> </div>
<div class="fields">City: <?php print $user->profile5_ ?> </div>
<div class="fields">Country: <?php print $user->profile4_ ?> </div>
</div>

and yet nothing changed tough i've renamed profiles to profile and i had put the <div class="profile"> over the user picture snippest...

Dublin Drupaller’s picture

it sounds like your theme isn't styled correctly...try switching your theme to something else..like BLUEMARINE (phptemplate version).

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

Dublin Drupaller’s picture

change your theme and post a link to your site so others can have a look...it's gone midnight here and I'm busy tomorrow so it's unlikely I can look at it until later night (tuesday).

Try changing themes to bluemarine(Phptemplate) and drop in your template.php + profile_profile.tpl.php file to the /bluemarine/ folder

remember it's the phptemplate version of bluemarine you need.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

famo’s picture

ok do you have a link for blumarine theme (phptemplate version)?
plz post the link if you have it..

famo’s picture

by the way there was no picture for the user, so i uploaded a picture for that user and showed the users list and oops the whole list is in the bottom of the page next to the footer, but the border is working properly...

so what to do in this case how to make the list to the top of the page as it suppose to be normaly?

im confused now..

Dublin Drupaller’s picture

Hi Famo..

Do this:

Step 1 of 2

  1. go to your active theme folder
  2. delete the template.php file
  3. delete the profile_profile.tpl.php file
  4. go to your www.example.com/profile page and click refresh

Step 2 of 2

  1. Click on the DOWNLOADS link at the top of this page.
  2. Click on the themes link
  3. If you are using Drupal 4.6 click on the 4.,6.x link.
  4. select the bluemarine theme (PHPTEMPLATE version) download it and install it.
  5. go to ADMINISTER -> THEMES on your site and make the new phptemplate version of bluemarine the default
  6. Click on your user list page
  7. Edit your STYLE.CSS file in your THEMES/BLUEMARINE/ folder to customise how your user list looks.

As an aside, I think you're trying to jump in too deep before getting familiar with the basics of Drupal.

Drupal is extremely powerful and extremely simple to use, but, the sheer depth of it does help if you understand the basics.

From the sounds of it, you understand how to upload/download and edit files...but it is worth spending some time looking at the HANDBOOK - in particular the BASIC SITE CONFIGURATION section, which includes a mix of Educational and instructional material.

As I said before, Famo, it's great that you're using Drupal, but the questions you are asking suggest you prefer to ask a question, sit back and wait for someone to bring you an answer, rather than hunting it down yourself.

As a tip. If you continue that way, you might find it difficult to get to know Drupal as you'll notice people ignoring your questions after a while.

When I started out, I asked some incredibly dumb questions as well..and the community was great, answering questions, but they nearly always came with a "by the way...you could have searched for that..or that's already covered in the handbooks". It was polite and subtle. But I got the hint fairly quickly.

I hope that helps, Famo. Drupal is superb, very powerful - I'm continually blown away with it - so it's worth taking the time to get to know it a little better.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

__Tango’s picture

In drupal-4.7, the name "profile_profile" has been changed to "profile_listing", so if you change:

function phptemplate_profile_profile(...

to

function phptemplate_profile_listing(...

and leave everything else the same, it should work. (i changed all references from profile_profile to profile_listing just for consistency, but i think the only one necessary is the one listed above.

Dublin Drupaller’s picture

thanks for flagging that.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

enxox’s picture

I've tried to apply what described in the handbook, with no results.
In the log page I found this error

PHPTemplate was instructed to override the profile_profile theme function, but no valid template file was found.

I can't understand what's wrong...

I'm working on a 4.6.5

Dublin Drupaller’s picture

Hi enxox,

I put together that handbook page...the error you're getting is becase Drupal can't find the profile_profile.tpl.php file in your active theme folder.

make sure you have named it correctly and put it in the same folder that you uploaded the template.php file (which should be your active theme folder).

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

enxox’s picture

I wrote tlp instead of tpl.......thank you!

enxox’s picture

how i can modify

<div class="fields">Nome utente: <?php print $user->name ?> </div>
to make the user name a link to user's profile?

Dublin Drupaller’s picture

Try this..

<div class="fields">Nome utente: <a href="/user/<?php print $user->uid; ?>" title ="click to view <?php print $user->name; ?>'s profile"><?php print $user->name; ?></a></div>

If you're not using clean urls..the link should obviously have the ?q= in front of it.

There are other ways of creating a link..that's just one way.

hope that helps
Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

enxox’s picture

Thank you very much!

Steve Blaze’s picture

If you are interested in adding the link to the user's picture as well just add part of the code provided by Dub in front of your image field. Insert this part of the code:<a href="/user/<?php print $user->uid; ?>". Be sure you use that last quote. I am using Drupal 4.7.3

<?php if($user->picture): ?>
<div class="picture">
<a href="/user/<?php print $user->uid; ?>"<img src="/<?php print $user->picture ?>">
</div>
<?php endif; ?>
<?php profile_load_profile($user->uid) ?>
<div class="custom_profiles">
<div class="fields"><a href="/user/<?php print $user->uid; ?>" title ="click to view <?php print $user->name; ?>'s profile"><?php print $user->name; ?></a></div>
<div class="fields"><?php print $user->profile_city ?></div>
</div>


I would like to ONCE again thank Dub for everything he does on this site. I have learned so much from his posts.

 

Steve Blaze

Administrator

NWiLive.com

geohelper’s picture

I highly recommend checking to see if a user has logged in before outputting a link to their profile. The reason is because non-admin users are unable to click and see a user's profile page if they have yet to log in.

if ($user->login != 0):
...
endif;

Note, this is an issue if you create a new user and notify them but they have yet to log in. This check should probably be added to drupal core since it results in a page not found.

rob101’s picture

I managed to use $zebra in the php to get images on alternating sides.

See more at this thread.

AstaC’s picture

This is an old thread so I do not even know if anyone will answer, but I will do a try. I have made a profile listing page according to this thread and it works fine. Thank you for that!

But I would like to do it to a table. I'm not very good at PHP but I do my best anyway.

I made it to a table with headers. But the header came above every user and every user got it's own table.

I would like to make a table with one headerrow with all the user's in the same table.
And I would like to put multiple fields in one cell and be able to change layout for every field and every cell in the table.

liliplanet’s picture

Hi AstaChattare,

Did you perhaps find a way to make the user list in table form? Have been trying for days now, have the same problem as you .. every user gets his own table.

Also perhaps do you know how to create pagination for the users?

Thank you for any help.
Lilian