@DivineDraft

Как вывести комментарии к каждому посту свои?

Каким образом можно вывести комментарии к каждому посту свои? На данный момент проблема состоит в том, что они не выводятся от слова совсем, даже не появляются на странице, но если, к примеру выводить их кол-во - выводится случайным образом и после обновления страницы значения меняется.

в файле singl.php, прописано:
<?php comments_template(); ?>
в файле comments.php:
<?php
/**
 * The template for displaying comments.
 */

/*
 * 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;
}
?>
<div id="comments" class="comments-area">
	<?php if ( have_comments() ) : ?>
		<h2 class="comments-title"><?php
			printf( _nx( '%s comment', '%s comments', get_comments_number(), 'comments title', 'blogfeedly' ), number_format_i18n( get_comments_number() ) );
			if ( comments_open() ) {
				echo ' &#47; <a href="#respond">' . __( 'Add your comment below', 'blogfeedly' ) . '</a>';
			}
		?></h2>
		<ol class="comment-list">
			<?php
			wp_list_comments( array( 
				'style'       => 'ol',
				'short_ping'  => true,
				'avatar_size' => 80
			) );
			?>
		</ol><!-- .commentlist -->
		<?php
		the_comments_navigation( array(
			'prev_text' => __( '&larr; Older comments', 'blogfeedly' ),
			'next_text' => __( 'Newer comments &rarr;', 'blogfeedly' )
		) );
		?>
	<?php
	endif;
	// If comments are closed and there are comments, let's leave a little note.
	if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
	?>
	<p class="comments-closed"><?php esc_html_e( 'Comments are closed.', 'blogfeedly' ); ?></p>
	<?php
	endif;
	comment_form( array(
		'comment_notes_after' => '',
	) );
	?>
</div><!-- .comments-area -->

в файле function:
add_theme_support(
		'html5',
		array(
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
		)
	);


В обсуждениях, записях, страницах - везде стоит "разрешить комментирование". Что я делаю не так? Уже не первый день пытаюсь найти проблема, никак не пойму, ранее не работал с WP.
  • Вопрос задан
  • 51 просмотр
Решения вопроса 1
PavelK
@PavelK
У Вас не указано к какому посту выводите.
В общем случае вызовы функций, которые относятся к посту, должны быть обёрнуты в
while ( have_posts() ) : the_post();

.....

endwhile;

https://codex.wordpress.org/Цикл_WordPress

Либо же указать конкретный пост с помощьюsetup_postdata();
https://codex.wordpress.org/Function_Reference/set...

Либо указывайте айдишник поста в каждом вызове метода, ответственный за вывод инфы о посте.
В общем, в зависимости от целей.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы