@LilBorsch

Почему разные id поста в файлах шаблона?

Если вывести id поста в шаблоне записи content-single она верная, а если вывести ее в файле single.php - то она другая и ваще от другого поста. В чем проблема?
Код ниже от single.php, id выводится не верный почему-то. В чем может быть проблема?
<?php get_header(); ?>

		<?php
		// Start the loop.
		while ( have_posts() ) :
			the_post();

			// Include the page content template.
			get_template_part( 'template-parts/content', 'single' );

			// If comments are open or we have at least one comment, load up the comment template.
			echo $post->ID;
			echo get_the_title();

			if ( comments_open() || get_comments_number() ) {
				comments_template();
			}

			// End of the loop.
		endwhile;

		?>

<?php get_footer(); ?>
  • Вопрос задан
  • 58 просмотров
Решения вопроса 1
deniscopro
@deniscopro Куратор тега WordPress
WordPress-разработчик, denisco.pro
1. Какой код в get_template_part( 'template-parts/content', 'single' ); ?
2. Если заменить echo $post->ID; на the_ID(); что выдает?
3. Если сделать вывод ID перед get_template_part( 'template-parts/content', 'single' ); что-то меняется?
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

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