Stok29
@Stok29
Web developer

Как избавиться от дублирования комментариев в wordpress?

Здравствуйте, столкнулся с проблемой дублирования комментариев у себя на сайте. Код single.php
<? get_header();
if (function_exists('setPostViews')) setPostViews(get_the_ID());
?>
		<section id="wrapper">
<div id="content">
<?php get_template_part( 'navigation', 'none' ); ?>
<?php get_template_part( 'streams', 'none' ); ?>



<div class="newsListFull">
<? if (have_posts()): 
				while (have_posts()): the_post(); ?>
	<h3 class='newsTitles'><?=the_title()?></h3>
	<div class="border_news">
	Автор: <?php the_author_link(); ?>, <?the_date('d-m-Y')?></div>
						<div class='news_content'><?  the_content() ?></div>
						<div class='border_news'>
						<div class='vk'><!-- Put this script tag to the <head> of your page -->
<script type="text/javascript" src="//vk.com/js/api/openapi.js?116"></script>

<script type="text/javascript">
  VK.init({apiId: 4956833, onlyWidgets: true});
</script>

<div id="vk_like"></div>
<script type="text/javascript">
VK.Widgets.Like("vk_like", {type: "mini"});
</script></div>
						</div>
						

						<h3 class="newsTitlesB_2">Другие новости</h3>
						<div class='other_news'>
						<?php $the_query = new WP_Query( 'showposts=3' ); ?>
						<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
						<a href="<?php the_permalink(); ?>"><div class='postBoxs'><?php echo get_the_post_thumbnail( $post->ID, 'thumbnail', array('class' => 'images') ); ?>
					<h3><?php the_title(); ?></h3></div></a><?php endwhile;?>
					<div style='clear: both;'></div></div>

							<h3 class='newsTitlesB_3'>Комментарии</h3>
				<?php comments_template(); ?> 
<?php endwhile; else: ?>
 
<p>Извините, но Вы ищете то чего здесь нет.</p>
 
<?php endif; ?>
</div>
<? get_sidebar() ?>
<? get_footer() ?>


Также заметил, когда убираю код

<h3 class="newsTitlesB_2">Другие новости</h3>
						<div class='other_news'>
						<?php $the_query = new WP_Query( 'showposts=3' ); ?>
						<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
						<a href="<?php the_permalink(); ?>"><div class='postBoxs'><?php echo get_the_post_thumbnail( $post->ID, 'thumbnail', array('class' => 'images') ); ?>
					<h3><?php the_title(); ?></h3></div></a><?php endwhile;?>
					<div style='clear: both;'></div></div>


комментарии перестают дублироваться, в чем косяк ? Я как понял цикл закрывается из за блока других новостей слишком рано или поздно. В общем прошу вашей помощи.
  • Вопрос задан
  • 338 просмотров
Решения вопроса 1
7kmarat
@7kmarat
впепеу
Проверьте это как у вас работает
<?php get_header(); ?>
<?php if (function_exists('setPostViews')) setPostViews(get_the_ID()); ?>

	<div class="newsListFull">

		<?php while ( have_posts() ) : the_post(); ?>

			<h3 class='newsTitles'><?php the_title() ?></h3>
			<div class="border_news">Автор: <?php the_author_link(); ?>, <?php the_date('d-m-Y') ?></div>
			<div class='news_content'><?php the_content() ?></div>
			<div class='border_news'>
				<div class='vk'><!-- Put this script tag to the <head> of your page -->
					<script type="text/javascript" src="//vk.com/js/api/openapi.js?116"></script>

					<script type="text/javascript">
						VK.init({apiId: 4956833, onlyWidgets: true});
					</script>

					<div id="vk_like"></div>
					<script type="text/javascript">
						VK.Widgets.Like("vk_like", {type: "mini"});
					</script>
				</div>
			</div>

			<h3 class="newsTitlesB_2">Другие новости</h3>
			<div class='other_news'>
				<?php
				$the_query = new WP_Query( 'showposts=3' );
				if ( $the_query->have_posts() ) {
					while ( $the_query->have_posts() ) {
						$the_query->the_post(); ?>
						<a href="<?php the_permalink(); ?>">
							<div class='postBoxs'><?php echo get_the_post_thumbnail( $post->ID, 'thumbnail', array('class' => 'images') ); ?>
								<h3><?php the_title(); ?></h3>
							</div>
						</a>
					<?php
					}
				}
				wp_reset_postdata();
				?>
				<div style='clear: both;'></div>
			</div>
			<?php
			}
			}
			wp_reset_query();
			} ?>

			<?php
				if ( comments_open() || get_comments_number() ) :
					comments_template();
				endif;
			?>

		<?php endwhile; ?>

	</div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
HeadOnFire
@HeadOnFire
PHP, Laravel & WordPress Evangelist
После использования вторичного лупа WP_Query используйте функцию wp_reset_postdata() для восстановления значения глобальной переменной $post.
Ответ написан
Комментировать
Ваш ответ на вопрос

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

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