vlady
vlady

Reputation: 600

Custom wordpress comments css class

Is there a way to add a custom class to comments that is a "reply comment" of a parent comment ?

*Note: my template use 'max_depth' => '1'.

Output code:

<div>
  <div class="comment-1"></div> // comment 1
    <div class="comment-2"></div> // reply 1
    <div class="comment-3"></a functiondiv> // reply 2
  <div class="comment-4"> // comment 2
</div>

I need a class for replies like:

<div>
  <div class="comment-1"></div> // comment 1
    <div class="comment-2" class="reply"></div> // reply 1
    <div class="comment-3" class="reply"></div> // reply 2
  <div class="comment-4"> // comment 2
</div>

A filter or a function ?

Edit:
Code that loops the comments is:

  1. In comments.php
    wp_list_comments(array('style' => 'div', 'type' => 'comment', 'max_depth' => '1' , 'callback' => 'comments_template'));

  2. In functions.php
    http://pastebin.com/4T5DiZY4

Upvotes: 0

Views: 934

Answers (1)

janw
janw

Reputation: 6662

The function comment_class() has a filter with the same name comment_class

function parent_comment_SE_14130085($classes, $class, $comment_id, $post_id) {
    $cur_comment = get_comment($comment_id);

    if ( ! empty( $cur_comment->comment_parent ) ) {
        $classes[] = 'nested';
    }
    return $classes;
}
add_filter('comment_class', 'parent_comment_SE_14130085', 10, 4);

Upvotes: 0

Related Questions