Support » Fixing WordPress » Control nested/child comments

  • Resolved Mark

    (@markjcasey)


    Hi guys

    This doesn’t refer to the styling of child comments, that’s pretty easy to change.

    I’m interested in adding or removing elements in a child comment. At the moment it just pulls everything from a normal comment.

    Is there a way to tell if a comment is a child so I can change things?

    I’ve been playing around with $comment_depth but not had much luck.

    Any ideas?

    Thanks : )

Viewing 7 replies - 1 through 7 (of 7 total)
  • You’ll need to create a custom callback function with condition such as

    if ($depth > 1) {
    	/* It's a nested comment */
    }

    Thread Starter Mark

    (@markjcasey)

    Thanks again for the reply Joseph… and thank you coco001 for the spam.

    I’m actually already using a custom comment display using the callback function.

    Where do I slot this condition into the function? I assume it would be here somewhere…

    if (!function_exists("custom_comment")) {
    	function custom_comment($comment, $args, $depth) {
    	   $GLOBALS['comment'] = $comment;

    Yes, it should be placed somewhere in that function. I can’t tell you exactly where and what to add because I don’t know what’s in it and what you’re trying to do.

    The conditions are $depth == 1 and $depth > 1 for parent and child comments respectively.

    Thread Starter Mark

    (@markjcasey)

    I’m trying to add some extra text on nested comments, that doesn’t appear on the parent ones.

    I’ve tried adding this just before the comment reply button from within my custom comment display.

    <?php if custom_comment($depth > 1) { ?>
    <p>Some text here</p>
    <?php } ?>

    That breaks my page though : (

    Try this:

    <?php if ($depth > 1) { ?>
    <p>Some text here</p>
    <?php } ?>

    Thread Starter Mark

    (@markjcasey)

    Ah, right. I didn’t need to mention the function again.

    Sorted, works a charm. Thanks again.

    You’re welcome. 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Control nested/child comments’ is closed to new replies.