W
W
WebforSelf2021-11-02 23:55:30
WordPress
WebforSelf, 2021-11-02 23:55:30

How can I collapse all replies to a comment?

The comment thread is rendered like this

<?php
wp_list_comments( array(
  'callback' => 'kurs_comment',
  'end-callback' => 'kurs_end_comment' 
) );
?>


function kurs_comment( $comment, $args, $depth ){
 
  ?><div <?php comment_class() ?> id="comment-<?php comment_ID() ?>">
    <div class="comment___item">
        <div class="comment__author"> 
    <?php echo get_avatar( $comment, 60, '', '', array( 'class' => 'comment___photo' ) ) ?>	
    <span class="comment__name cormorant"><?php comment_author() ?></span>
    </div>
      <div class="comment__content">
        <span class="comment__date"><?php comment_date( 'j F Y в H:i' ) ?> <?php edit_comment_link( 'Изменить', '<div class="edit__comment">(', ')</div>'); ?></span>
        <div class="comment__text"><?php comment_text() ?></div>
        <?php comment_reply_link(); ?>
      </div>
    </div>
    <?php // без закрывающего </li> (!)
 
}

function kurs_end_comment( $comment, $args, $depth ){	
  echo '</div>';
}


all answers to the main comment are wrapped in
ul class="children"

How to make it so that instead of the answer thread, there was a link
Expand (5 comments)
For now, the idea is only to find by the children class and put a link in front of it and do display:none for the comment wrapper itself;

And by the way, I noticed an important thing, for some reason it does not work in my form. Although it seems like the rest of all the hooks work fine. UPD.

<?php comment_reply_link(); ?>



<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>

Works with arguments.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WebforSelf, 2021-11-03
@WebforSelf

Suddenly someone has to.

/*сворачиваем  комменты*/
$(".children").after("<a href='#' class='collapce_comment'>Развернуть</a>");

  $('.collapce_comment').click(function(){
    $(this).closest('.comment').find('.children').slideToggle(300, function(){
      if ($(this).is(':hidden')) {
        $(this).parent().find('.collapce_comment').html('Развернуть');
      } else {
        $(this).parent().find('.collapce_comment').html('Свернуть');
      }							
    });
    return false;
  });

the essence is as follows, I add a button after the block with responses to the comment.
Further, when it is clicked, I simply open or close this block.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question