Fredrik
Fredrik

Reputation: 635

Decide if comment is a reply to another comment

I have searched Googled for this quite long now. I'm doing my own theme based on the Sandbox theme. Now I have come to the comment-section.

The Sandbox theme doesn't add nested comment (if the comment is a reply to another comment). Which makes the comment part a bit messy to figure out which is a reply to another comment or not.

Is there any CSS class I can add to my comment.php file to print out a certain CSS class if the comment is a reply or not? This because I want the reply to be indented from the left a bit under the comment it is an reply to.

Upvotes: 0

Views: 2093

Answers (3)

Brent
Brent

Reputation: 2971

The WordPress function comment_class() adds a variety of classes, one of which is "comment depth." On the styling front, it tells you if it's a reply to another comment.

If you need to know for programmatic reasons, @pycior's answer should do the trick.

http://codex.wordpress.org/Function_Reference/comment_class

Upvotes: 2

Lukasz Wojciak
Lukasz Wojciak

Reputation: 89

You should probably use firebug to check the source of the template and see if there are any extra classes. If not, You should check if a comment has a parent in your comment loop and change/add the class there.

<?php 
$comments = get_comments($post_ID);
foreach($comments as $comment) :
   if ($comment->comment_parent>0) {
      echo('<div class="comment subcomment">'.$comment->comment_author . '<br />' . $comment->comment_content.'</div>');
   } else {
      echo('<div class="comment">'.$comment->comment_author . '<br />' . $comment->comment_content.'</div>');
   }
endforeach;
?>

And then just style the class trough css.

Upvotes: 1

sticksu
sticksu

Reputation: 3738

You can try to use http://codex.wordpress.org/Function_Reference/wp_list_comments . Just write the PHP code and your comments will appear on your page nested, and then you can make you own CSS so it will look the way you want.

Upvotes: 0

Related Questions