Answer the question
In order to leave comments, you need to log in
How to display a link to the parent comment in tree-like comments in a specific child comment?
On a WordPress site, to display comments on post pages of an arbitrary "movies" type:
- in the "single-movies.php" template (for a separate post page of the "movies" type) a function is used
- a custom file comments.php has been created with the following content: comments_template();
<?php if (comments_open()) { ?>
<?php if (get_comments_number() == 0) { ?>
<?php } else { ?>
<ul class="commentlist">
<?php
function my_comment($comment, $args, $depth){
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="row comment_area">
<div class="comment_author_ava col-xs-1">
<span class="glyphicon glyphicon-user" aria-hidden="true"></span>
</div>
<div class="comment_content col-xs-11">
<div class="comment_author_name">
<?php printf(__('<span>%s</span>'), get_comment_author_link()) ?>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<em><?php _e('Ваш комментарий ожидает модерации') ?></em>
<br>
<?php endif; ?>
<?php comment_text() ?>
<div class="reply">
<span class="date"><?php printf(__('%1$s, %2$s'), get_comment_date(), get_comment_time()) ?></span> <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</div>
</div>
</div>
<?php }
$args = array(
'reply_text' => 'Ответить',
'callback' => 'my_comment'
);
wp_list_comments($args);
?>
</ul>
<?php } ?>
<?php
$fields = array(
'author' => '<p class="comment-form-author"><input type="text" id="author" name="author" class="author" value="' . esc_attr($commenter['comment_author']) . '" placeholder="Введите ваше имя" pattern="[A-Za-zА-Яа-я -.]{2,}" maxlength="45" autocomplete="on" tabindex="1" required' . $aria_req . '></p>',
'email' => '<p class="comment-form-email"><input type="email" id="email" name="email" class="email" value="' . esc_attr($commenter['comment_author_email']) . '" placeholder="Введите ваш email" maxlength="90" autocomplete="on" tabindex="2" required' . $aria_req . '></p>'
);
$args = array(
'comment_notes_before' => '',
'comment_notes_after' => '',
'title_reply' => 'Добавить комментарий',
'comment_field' => '<p class="comment-form-comment"><textarea id="comment" name="comment" class="comment-form" cols="45" rows="4" aria-required="true" placeholder="Напишите ваш комментарий" required></textarea></p>',
'label_submit' => 'Отправить',
'fields' => apply_filters('comment_form_default_fields', $fields)
);
comment_form($args);
?>
<?php } else { ?>
<h3>Обсуждения закрыты для данной страницы</h3>
<?php }
?>
Answer the question
In order to leave comments, you need to log in
Apparently, $depth in the my_comment function reflects the depth of the comment. Based on it, you can store the comment id of the previous depth, for example, using GLOBALS['last_comment_id'] and $GLOBALS['depth'] defined before calling comments_template().
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question