Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Per Usergroup Post Color

edited May 2012 in Vanilla 2.0 - 2.8

Hi,

I'm trying to implement a per usergroup post color for my forums, but running into a wall in the implantation. I have the CSS that appropriately changes the posts' font color, but trying to get it to apply only to a certain role doesn't appear to be working. I Google'd it in an attempt to see if there was a solution, but the only two threads I came across didn't have solutions that worked for me.

Here and here for reference.

.role-administrator .Comment .Meta .Author a { color: #FFC125 !important; }
or similar doesn't seem to do anything. How do I also handle the fact that I've changed the name of the group? I tried referencing it by the role ID number, but I can't get anything to work.

Best Answer

  • peregrineperegrine MVP
    edited May 2012 Answer ✓

    You probably have to write a plugin or go to the helper_functions.php and add a .roletitle class to the discussion. or if you used a plugin - you may be able to modify it there. But since you didn't mention a plug-in I assume it doesn't refer to a plugin.

    then add a css rule for it.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Answers

  • You habe to look at how the comment divs are being generated and add the something to uniquely identify them with the role or userid or whatever.

    This will require a plugin or a theme that overrides some core files.

  • I figured it out partially, as RoleTitles does append some CSS rules to the .Comment container formatted like: .role-[role-title].

    But the problem is this only affects Comments and not the original discussion. I tried modifying RoleTitles to append CSS definitions to the .Item class, but was running into a wall there. If somebody knows how to do that, then please go ahead else if I figure it out I'll post it here!

  • throw up a link to your site, so we can see.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • edited May 2012

    peregrine said:
    throw up a link to your site, so we can see.

    http://believe-tera.com/index.php/forum#/discussion/5/test-discussion

  • peregrineperegrine MVP
    edited May 2012 Answer ✓

    You probably have to write a plugin or go to the helper_functions.php and add a .roletitle class to the discussion. or if you used a plugin - you may be able to modify it there. But since you didn't mention a plug-in I assume it doesn't refer to a plugin.

    then add a css rule for it.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Got it. In discussion.php I replaced

    <

    div class="Item-Body"> with <?php $Object = GetValue('Object', $Sender->EventArguments); $CssRoles = $Object ? GetValue('Roles', $Object, array()) : FALSE; foreach ($CssRoles as &$RawRole) $RawRole = 'role-'.str_replace(' ','_', strtolower(Gdn_Format::Url($RawRole))); echo '<div class="Item-Body ' . implode(' ',$CssRoles) . '">'; ?>
    Works great now.

  • thats one for the WIKI

    There was an error rendering this rich post.

  • It's kind of a cheap workaround. If I had the time, I'd develop it into a full plugin. Maybe I should, I'll look into it.

  • fh111fh111 ✭✭

    cool thanks for the solution! i once tried to figure out something similar, only difference was that i wanted to set a post color for specific usernames

  • fh111 said:
    cool thanks for the solution! i once tried to figure out something similar, only difference was that i wanted to set a post color for specific usernames

    I believe the concept is very similar; you can just append their user ID # in the exact same way that I appended their role title and then theme each individual user.

  • fh111fh111 ✭✭

    thanks, won't be necessary anymore, because back then i just wanted to give the admins a certain color and i could do that with your solution. but i actually decided to not do that for equality reasons

  • you showed fortitude and stamina.  
    
    You could probably do it pretty easily in a plugin with these two 
    
    public function DiscussionController_BeforeCommentDisplay_Handler($Sender) {  
             $CssItem = $Sender->EventArguments['CssClass'];      
    
            // code to process roletitle class
    
    
     /* you could probably do a bunch of it by just adding the new classes to CssClass
      }
    
     public function CategoriesController_BeforeCommentMeta_Handler(&$Sender) {
            $this->DiscussionController_BeforeCommentMeta_Handler($Sender);
        } 
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • PewPewK said:
    It's kind of a cheap workaround. If I had the time, I'd develop it into a full plugin. Maybe I should, I'll look into it.

    There is already a 'usergroup' or 'roletitle' plugin or something. Can you see if you can adjust that plugin? (if the plugin hasn't been updated in a while...)

    There was an error rendering this rich post.

  • UnderDog said:

    PewPewK said:
    It's kind of a cheap workaround. If I had the time, I'd develop it into a full plugin. Maybe I should, I'll look into it.

    There is already a 'usergroup' or 'roletitle' plugin or something. Can you see if you can adjust that plugin? (if the plugin hasn't been updated in a while...)

    I finished developing the plugin and I'm currently beta-testing/trying to make sure it doesn't break anything. All the code is based off the RoleTitles plugin and (unfortunately) slightly conflicts if you have both installed, but it doesn't seem to break anything, just sets all .Comment container ID's to "Comment role-admin role-admin". Adjusting the CSS still works though.

  • Which conflicts do you get? Is RoleTitle an old plugin? Show conflicts in the changelog?

    There was an error rendering this rich post.

  • @PewPewK

    I looked at your link again. I'm not that great with css, but it seems like you've got lots of extra superfluous div tags to add classes, when you could just throw multiple classes into one or two div tags. Or this could be a result of using the two plugins.

         <div class="role-web-master">   
           <div class="Item-BodyWrap">
         <div class="Item-Body">
           <div class="Message">   
                    Lorem ipsum ...
            </div>
            </div>
           </div>
           </div>
          </div>
    
    
    The duplication you were talking about
    
    `<li class="Item ItemComment role-guild-member role-guild-member" id="Comment_11">`
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Right, <li class="Item ItemComment role-guild-member role-guild-member" id="Comment_11"> is caused by RoleTitles and my plugin conflicting as they both run code to affix the role CSS to the Comment container.

    I'm trying to figure out how to update the CssClass for Item-Body, but the similar code that updates the Comment container doesn't do anything in when changed to the Discussion implementation. I'm better at CSS, I've never touched PHP in my life so I'm just trying to go off my general C/Java programming knowledge here.

  • peregrineperegrine MVP
    edited May 2012

    take a look a ignore user plugin to add to append to classes where Item class exists
    then try some css

    e.g.

    li.role-guild-member .Message {

    div.role-guild-member .Message {

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.