• Hi!

    So, I’ve created a new role (with the Capability Manager plugin) for to some people considered as “VIP”. I want to attribute to them a specific comment css (to change the background of the comment div).

    How can I do that ? I use the odd/even for the actual display.

Viewing 5 replies - 1 through 5 (of 5 total)
  • have a close look into commments.php of your theme, to see if you can identify the code section where the individual comment get output.

    in twenty ten, this is the line with ‘wp_list_comments()’ which uses a callback function, located in functions.php;
    this line generates the css classes for the individual comment:

    <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">

    expanded to create new comment css classes for user roles:

    <?php $user = new WP_User( $comment->user_id );
    if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
    	foreach ( $user->roles as $role ) $roles[] = 'by'.$role; } ?>
    	<li <?php comment_class($roles); ?> id="li-comment-<?php comment_ID(); ?>">

    it does for instance create a css class .byadministrator for an admin commenter, copying the structure of the existing comment classes, such as .byuser or .bypostauthor;
    no idea if this would get the VIP role of your plugin.

    – thanks to the contributors of this thread: https://www.ads-software.com/support/topic/get-a-users-role-by-user-id?replies=20

    Thread Starter CuberToy

    (@cubertoy)

    I use
    <?php wp_list_comments('avatar_size=50&type=comment&callback=mytheme_comment'); ?>

    in my theme.

    And here is what “mytheme_comment” look like

    function mytheme_comment($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment; ?><?php global $cmntCnt; ?>
       <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
         <div id="comment-<?php comment_ID(); ?>">
          <div class="comment-author vcard">
            <?php echo get_avatar($comment); ?>
             <?php printf(__('<cite class="fn">%s</cite> <span class="says">dit :</span>'), get_comment_author_link()) ?>
          </div>
          <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">(#<?php echo $cmntCnt+1; ?>) <?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'  ','') ?></div>
    
          <?php comment_text() ?>
    
          <div class="reply">
             <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
          </div>
         </div>
    <?php $cmntCnt = $cmntCnt + 1; ?>
    <?php
            }

    Ok that was for more information about my code. I’ll try your trick right now and reply.

    EDIT : Ok so, everything work for admin and user. I will now try to adapt it for my special role… fingers cross (highly doubt right now).

    EDIT 2 : Ok, it works ! For those who need the same think here is what I did…

    Simply name you css class with your capability name. (.by[name])
    For exemple :
    Capability name : vip
    css class : .byvip {}

    Thank you very much alchymyth !

    Thread Starter CuberToy

    (@cubertoy)

    Oh just notice (I was trying just with border) but the .by don’t overlap the odd/even class…

    if your styles get ‘ignored’ try forcing them with !important

    for instance:

    .byvip { border: 2px solid #123!important; }

    Thread Starter CuberToy

    (@cubertoy)

    Oh yeah, totally forget that trick ><

    Thank you again ! You’ve been really helpfull.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Special comment color for specific role’ is closed to new replies.