Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
themes-topic
Colors in username based on user group
Avatar
sptab
Member
sp_UserOfflineSmall Offline
Oct 1, 2012 - 10:21 am

Hello,

I'd like to customize my theme so the usernames would show in a different color, based on their user group (mainly for moderators and admins). I'll first apply to that display in the online list that appears at the bottom of each page and maybe later at other places like in each post profile...

I'm seeking recommendations to achieve that:

- will I be able to cleanly implement this without modification to SP core source code ?

- is the user group information easily available so I don't need to do extra queries ? 

Thank you.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Oct 1, 2012 - 11:28 am

This functionality is already built into the username display on topic view for each poster. A bunch of special classes are added to each post row so you can specifically style each user based on things like user type, memberships, ranks, etc.

However this is not true of the stats. This will be quite problematic for the stats since the data is not available without more queries. Additionally, the stats are cache so potential for stale data.

If you want to globally do this for every user name displayed, you would want to affect the global display name function. I believe there is a filter on the generation of the html that would allow you to add classes to the display in order to customize the output.

But you would still need to do the additional queries to get the needed data.

Avatar
sptab
Member
sp_UserOfflineSmall Offline
Oct 1, 2012 - 4:51 pm

Thanks for the quick answer, that gives me some directions for my implementation.

I'll come back to ask if needed.

Cheers.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Oct 1, 2012 - 5:18 pm

Sorry can't be more specific until Wednesday when back. Think routine something like sp_build_name_display().

If filter, should be easy, although extra query per name, to add a class. If no filter, we can add one.

Avatar
sptab
Member
sp_UserOfflineSmall Offline
Oct 15, 2012 - 12:57 pm

I have been checking for different options, including your suggestions.

A good solution I can think of would be to modify (probably hardcoding the username and colors at first) the sp_filter_name_display function in sp-api-filters.php, so the username color display would be consistent everywhere on the forum. Do you see any border effect of doing so ?

Any suggestions on how to do that change without modifying sp-api-filters.php in the core code ? 

I see the following code at the end of sp_filter_name_display function

$content = apply_filters('sph_display_name_filter', $content);

but I am not sure on the proper way to handle this in my custom theme code ?

Thank you.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Oct 15, 2012 - 9:17 pm

you are not going to be able to do what you want in that filter routine or using the sph_display_name_filter...  that only gets the username... you wont be able to add any html or styling because when output it usually will already be within some html tags...

as I said in post #4, I think you want sp_build_name_display() function... Its where we output users names... now I cannot guarantee its all user name displays, but certainly the ones we allow linking to the profile on... 

if linking to a profile, the routine it calls will be:  sp_attach_user_profile_link()

you will see html generated there where you could add the specific classes you want for color... you might need to do

$user = sp_get_user($userid);

in there to set up a use object...  then you can get at that users memberships via $user->memberships

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 620
Members: 17365
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10128
Posts: 79626