Почему не отображается блок 'title_reply_to' в файле сomments.php?
Имеется проблема отображения кнопки ответа для parent комментариев ('title_reply_to') и соответственно children комментариев в файле сomments.php.
Делаю всё согласно доке WordPress'а, перепробовал десятки подсказок в решении проблемы. Что исправить в данном коде для отображения 'title_reply_to'?
<?php /** * The template for displaying comments * * This is the template that displays the area of the page that contains both the current comments * and the comment form. * * @link https://developer.wordpress.org/themes/basics/template-hierarchy/ * * @package wp-eo-blog */ /* * If the current post is protected by a password and * the visitor has not yet entered the password we will * return early without loading the comments. */ if ( post_password_required() ) { return; } ?> <?php if ( have_comments() ) : ?> <div class="comments"> <h4 class="comments-title"> <!-- COMMENTS TITLE --> <?php $comments_number = get_comments_number(); if ( '1' === $comments_number ) { echo 'One Comment'; } else { echo $comments_number . ' Comments'; } ?> </h4> <!-- COMMENT LIST --> <div class="comment-list"> <?php wp_list_comments( array( 'style' => 'div', 'short_ping' => true, 'avatar_size' => 50, ) ); ?> </div> <!-- COMMENTS --> <?php $defaults = [ 'fields' => [ 'author' => '<p class="comment-form-author"> <label class="b3__demibold text-navy500" for="author">' . __( 'Name' ) . ( $req ? ' <span class="required text-red500">*</span>' : '' ) . '</label> <input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . $html_req . ' /> </p>', 'email' => '<p class="comment-form-email"> <label class="b3__demibold text-navy500" for="email">' . __( 'Email' ) . ( $req ? ' <span class="required text-red500">*</span>' : '' ) . '</label> <input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" aria-describedby="email-notes"' . $aria_req . $html_req . ' /> </p>', 'url' => '<p class="comment-form-url display-none"> <label class="b3__demibold" for="url">' . __( 'Website' ) . '</label> <input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /> </p>', 'cookies' => '<p class="comment-form-cookies-consent display-none">'. sprintf( '<input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"%s />', $consent ) .' <label for="wp-comment-cookies-consent">'. __( 'Save my name, email, and website in this browser for the next time I comment.' ) .'</label> </p>', ], 'comment_field' => '<p class="comment-form-comment"> <label class="b3__demibold text-navy500" for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required="required"></textarea> </p>', 'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . ' </p>', 'logged_in_as' => '<p class="logged-in-as">' . sprintf( __( '<a href="%1$s" aria-label="Logged in as %2$s. Edit your profile.">Logged in as %2$s</a>. <a href="%3$s">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . ' </p>', 'comment_notes_before' => '<p class="comment-notes display-none"> <span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>'. ( $req ? $required_text : '' ) . ' </p>', 'comment_notes_after' => '', 'id_form' => 'commentform', 'id_submit' => 'submit', 'class_container' => 'comment-respond', 'class_form' => 'comment-form', 'class_submit' => 'submit', 'name_submit' => 'submit', 'title_reply' => __( 'Leave a Reply' ), 'title_reply_to' => __( 'Leave a Reply to %s' ), 'title_reply_before' => '<h5 id="reply-title" class="comment-reply-title">', 'title_reply_after' => '</h5>', 'cancel_reply_before' => ' <small>', 'cancel_reply_after' => '</small>', 'cancel_reply_link' => __( 'Cancel reply' ), 'label_submit' => __( 'Post Comment' ), 'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />', 'submit_field' => '<p class="form-submit">%1$s %2$s</p>', 'format' => 'xhtml', ]; comment_form( $defaults ); ?> <!-- PAGINATION COMMENTS --> <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?> <nav class="navigation comment-navigation" role="navigation"> <div class="nav-previous"><?php previous_comments_link( 'Older Comments' ); ?></div> <div class="nav-next"><?php next_comments_link( 'Newer Comments' ); ?></div> </nav> <?php endif; ?> </div> <?php endif; ?> <?php if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) : ?> <p class="no-comments">Comments are closed.</p> <?php endif; ?> |
<?php /** * The template for displaying comments * * This is the template that displays the area of the page that contains both the current comments * and the comment form. * * @link https://developer.wordpress.org/themes/basics/template-hierarchy/ * * @package wp-eo-blog */ /* * If the current post is protected by a password and * the visitor has not yet entered the password we will * return early without loading the comments. */ if ( post_password_required() ) { return; } ?> <?php if ( have_comments() ) : ?> <div class="comments"> <h4 class="comments-title"> <!-- COMMENTS TITLE --> <?php $comments_number = get_comments_number(); if ( '1' === $comments_number ) { echo 'One Comment'; } else { echo $comments_number . ' Comments'; } ?> </h4> <!-- COMMENT LIST --> <div class="comment-list"> <?php wp_list_comments( array( 'style' => 'div', 'short_ping' => true, 'avatar_size' => 50, ) ); ?> </div> <!-- COMMENTS --> <?php $defaults = [ 'fields' => [ 'author' => '<p class="comment-form-author"> <label class="b3__demibold text-navy500" for="author">' . __( 'Name' ) . ( $req ? ' <span class="required text-red500">*</span>' : '' ) . '</label> <input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . $html_req . ' /> </p>', 'email' => '<p class="comment-form-email"> <label class="b3__demibold text-navy500" for="email">' . __( 'Email' ) . ( $req ? ' <span class="required text-red500">*</span>' : '' ) . '</label> <input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" aria-describedby="email-notes"' . $aria_req . $html_req . ' /> </p>', 'url' => '<p class="comment-form-url display-none"> <label class="b3__demibold" for="url">' . __( 'Website' ) . '</label> <input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /> </p>', 'cookies' => '<p class="comment-form-cookies-consent display-none">'. sprintf( '<input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"%s />', $consent ) .' <label for="wp-comment-cookies-consent">'. __( 'Save my name, email, and website in this browser for the next time I comment.' ) .'</label> </p>', ], 'comment_field' => '<p class="comment-form-comment"> <label class="b3__demibold text-navy500" for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required="required"></textarea> </p>', 'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . ' </p>', 'logged_in_as' => '<p class="logged-in-as">' . sprintf( __( '<a href="%1$s" aria-label="Logged in as %2$s. Edit your profile.">Logged in as %2$s</a>. <a href="%3$s">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . ' </p>', 'comment_notes_before' => '<p class="comment-notes display-none"> <span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>'. ( $req ? $required_text : '' ) . ' </p>', 'comment_notes_after' => '', 'id_form' => 'commentform', 'id_submit' => 'submit', 'class_container' => 'comment-respond', 'class_form' => 'comment-form', 'class_submit' => 'submit', 'name_submit' => 'submit', 'title_reply' => __( 'Leave a Reply' ), 'title_reply_to' => __( 'Leave a Reply to %s' ), 'title_reply_before' => '<h5 id="reply-title" class="comment-reply-title">', 'title_reply_after' => '</h5>', 'cancel_reply_before' => ' <small>', 'cancel_reply_after' => '</small>', 'cancel_reply_link' => __( 'Cancel reply' ), 'label_submit' => __( 'Post Comment' ), 'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />', 'submit_field' => '<p class="form-submit">%1$s %2$s</p>', 'format' => 'xhtml', ]; comment_form( $defaults ); ?> <!-- PAGINATION COMMENTS --> <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?> <nav class="navigation comment-navigation" role="navigation"> <div class="nav-previous"><?php previous_comments_link( 'Older Comments' ); ?></div> <div class="nav-next"><?php next_comments_link( 'Newer Comments' ); ?></div> </nav> <?php endif; ?> </div> <?php endif; ?> <?php if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) : ?> <p class="no-comments">Comments are closed.</p> <?php endif; ?>
Дополнительно:
Ответы:
Если это страница то в свойствах попробуйте отметить галкой "Разрешить комментарии" Если это запись то в свойствах так же отметьте галкой "Разрешить комментарии"
"Разрешить отклики". Так же проверьте, отмечены ли поля в "Настройки" - "Обсуждение", "Разрешить оставлять комментарии к новым записям" и " Разрешить древовидные (вложенные) комментарии глубиной". И вообще, проверьте правильность настроек на станице "Настройки обсуждения". А в коде искать причину надо только в том случае если его меняли. Если нет, то дело в настройках.
Опишите проблему, и специалист поможет с настройкой, исправлением ошибки или доработкой сайта. Подберём понятный план работ без лишней переписки.
Пока нет других ответов. Будьте первым, кто поможет автору.
Ответить на вопрос

title_reply_to— это не “кнопка ответа” и не отдельный блок для parent/children комментариев. Это текст заголовка формы ответа, который показывается, когда пользователь нажал “Ответить” на конкретный комментарий. Чтобы он работал, на странице должны быть корректно выведены ссылки reply и подключён стандартный JS комментариев WordPress.В шаблоне комментариев форма должна вызываться через
comment_form()с параметрами:comment_form([ 'title_reply' => 'Оставить комментарий', 'title_reply_to' => 'Ответить на комментарий %s', 'cancel_reply_link' => 'Отменить ответ', ]);
А в выводе списка комментариев должна быть ссылка ответа:
comment_reply_link(array_merge($args, [ 'reply_text' => 'Ответить', 'depth' => $depth, 'max_depth' => $args['max_depth'], ]));
Также в теме должен подключаться скрипт:
add_action('wp_enqueue_scripts', function () { if (is_singular() && comments_open() && get_option('thread_comments')) { wp_enqueue_script('comment-reply'); } });
И в настройках WordPress должны быть включены древовидные комментарии: “Настройки → Обсуждение → Разрешить древовидные комментарии”.
Если Вы ожидаете, что
title_reply_toпоявится возле каждого parent-комментария, это неверное ожидание. Он появляется в заголовке формы, когда форма переносится под конкретный комментарий после клика “Ответить”. Если кнопки ответа нет, проблема не вtitle_reply_to, а в том, что не выводитсяcomment_reply_link(), не передан depth/max_depth или не подключёнcomment-reply.Проверьте ещё, что
wp_head()иwp_footer()есть в теме. Безwp_footer()стандартный JS ответа на комментарий может не подключиться, и форма не будет переноситься.