XF 2.0 Giving users of 1 user group, different colors on their usernames

Frode789

Well-known member
So I have a premium user group, and I want them to be able to have differently colored usernames. F.ex. member A blue, B red, etc. How can I achieve that? I don't want to make a new user group every time a new user becomes a member of my premium group.
 
So, what would the color be based on? Just randomly assigned? User specified? Groups of users? It starts getting really complicated and I think the result would be ugly/confusing if every user has a different color. If it's groups, that's the easiest - you can have different groups for different levels of premiumness or based on number of posts, etc. and just promote people to those groups. It's easy to change the color of user name in groups.
 
So, what would the color be based on? Just randomly assigned? User specified? Groups of users? It starts getting really complicated and I think the result would be ugly/confusing if every user has a different color. If it's groups, that's the easiest - you can have different groups for different levels of premiumness or based on number of posts, etc. and just promote people to those groups. It's easy to change the color of user name in groups.

User specific, whatever the user want. He request a color, and I'll assign it, as long as it isn't a color that looks completely off on the style. Yes I'm aware that you can assign it to user groups, and that would be the easiest way of course. That said, I don't want a to split it into many different user groups. I want all my lifetime premiums in one group :)

Nono, I doubt it would come to that. It is a premium, lifetime option, which means there will be few users with it. I currently only have 3, out of about 160 members.
 
User specific, whatever the user want. He request a color, and I'll assign it, as long as it isn't a color that looks completely off on the style. Yes I'm aware that you can assign it to user groups, and that would be the easiest way of course. That said, I don't want a to split it into many different user groups. I want all my lifetime premiums in one group :)

Nono, I doubt it would come to that. It is a premium, lifetime option, which means there will be few users with it. I currently only have 3, out of about 160 members.
OK, here's how to do (tested it on my forum):
  1. Create a custom user field:
    • Field ID: usernameColor
    • Title: Username color
    • Description: Username color
    • Type: Drop down
    • Possible choices:
      Enter following in Value and Text fields:
      • Black Black
      • Blue Blue
      • Brown Brown
      • Green Green
      • Orange Orange
      • Pink Pink
      • Purple Purple
      • Red Red
      • Yellow Yellow

        You can also specify a rgb(x,x,x), #xxxxxx hex value, or any other standard HTML color name as the value (See https://www.w3schools.com/colors/colors_names.asp)
    • Uncheck User Editable (unless you want to modify the user details template to conditionally show based on user group).
    • Check Moderator Editable
  2. Then, edit message_macros template, changing:
    HTML:
    <h4 class="message-name"><xf:username user="$user" rich="true" defaultname="{$fallbackName}" itemprop="name" /></h4>
    to
    HTML:
    <xf:if is="$user.Profile.custom_fields.usernameColor">
        <h4 class="message-name"><xf:username user="$user" rich="true" defaultname="{$fallbackName}" itemprop="name" style="color: {$user.Profile.custom_fields.usernameColor} !important" /></h4>
    <xf:else />
        <h4 class="message-name"><xf:username user="$user" rich="true" defaultname="{$fallbackName}" itemprop="name" /></h4>
    </xf:if>
 
Last edited:
Note: FWIW I would just use a custom title and/or banner. If anything, allow changing the color of the title, using this same approach (just with the xf:title on the next line of message_macros). Changing the color of a hyperlink is bad.
 
Top Bottom