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.

Adding role title and username to discussions li CSS class

edited July 2011 in Vanilla 2.0 - 2.8
I'd like to be able to add the username and his role (or multiple roles) as CSS hooks on the discussions page, so that each li is styled with a class that includes the username and roles. This would make customizing individual posts, or posts by role, very easy (with CSS).

I was able to accomplish this with the username, so each of my discussion posts has the username added as a style element (so, for instance, my html will look like this:
 <li class="Item Comment Jim" id="Comment_19">
, where "Jim" is the customized addition to the style. Now I can go in and customize Jim's posts with unique styles, if I so wish. But now I realize I would be better served if I add the role as well, so that I can get:
<li class="Item Comment Jim moderator" id="Comment_19">
How do I get "moderator" or "member" added to the CSS style?

I think I'm getting hung up on retrieving the roles from an array. I've studied the database table, and was able to retrieve the username, but getting the roles is harder. One, does anyone have an easy solution to adding this to the discussions.php file?

Here's what I added to my discussions.php already, to get the li style to add the username. At the top of the file I included this:
if (!function_exists('UserNameClass')) {
   function UserNameClass($User, $CssClass = '', $Options = array()) {
      $User = (object)$User;
      if ($CssClass != '')
         $CssClass = ' class="'.$CssClass.'"';

      return $User->Name;

Then, where I am adding the extra style to the class tag, I changed the code to this:
<li class="<?php echo $CssClass; ?> <?php echo UserNameClass($Author);?>" id="<?php echo $Id; ?>">
   <div class="Comment">
      <div class="Meta">
Okay. How do I do this to get the roles?

Lastly, I think this would be an easy and nonintrusive addition to the core files. Easy addition I would think.
Sign In or Register to comment.