У меня есть 3 категории записей на сайте, и мне нужно сделать так, чтобы на странице результатов поиска записи, которые относятся к определенной категории выводились по шаблону, заданному для этой категории.
Сейчас цикл выглядит вот так
<?php 	
   if ( have_posts() ) : 
?>
<?php
   while ( have_posts() ) :
      the_post();?>
         <div class="main-part__post post get-post">
            <div class="post__image search-img" style="background-image: url(<?php echo get_the_post_thumbnail_url() ?>); background-size: cover; background-position: center center;">
            </div>
            <div class="post__text-part searching-text">
               <h4 class="post__text-part_heading"><?php the_title();?></h4>
	       <div class="post__text-part_info info">
	          <div class="info__autor-part">
	 	     <img class="info__autor-part_img" src="<?php echo get_template_directory_uri();?>/img/post/autor-icon.png">
	 		<h5 class="post__text-part_autor"><?php the_author(); ?></h5>
	 	   </div>
	 	   <hr class="post__text-part_line">
	 	   <div class="info__date-part">
	 	      <img class="info__date-part_img" src="<?php echo get_template_directory_uri();?>/img/post/date-icon.png">
	 	      <h5 class="post__text-part_date">Realese date: <?php echo get_the_date('d.m.y');?></h5>
	 	   </div>
	 	</div>
	 	<p class="post__description"><?php echo get_the_excerpt();?></p>
	 	<a class="post__button" href="<?php echo get_permalink(); ?>">Read More</a>
            </div>	 
      </div>
				
<?php
	endwhile;
?>
	<div style="margin-left: 4%;">
	<?php
	the_posts_pagination($args = array(
	'show_all'     => false, 
	'end_size'     => 1,   
	'mid_size'     => 1,   
	'prev_next'    => true, 
	'prev_text'    => __('« Previous'),
	'next_text'    => __('Next »'),
	'add_args'     => false, 
	'add_fragment' => '',     
	'screen_reader_text' => __( 'Posts navigation' ),
));
?>
	</div>
</div>
<?php
	else :
		get_template_part( 'template-parts/content', 'none' );
endif;
?>
 
Нужно чтобы для каждого поста, определялась его категория и в зависимости от нее пост выводился по определенному шаблону.
Итак, вот что у меня получилось в итоге
<?php 	
	if ( have_posts() ) : ?>
		<?php
			while ( have_posts() ) :
				the_post();
				$category = get_the_category($post->ID);
				$current_cat_id = $category[0]->cat_ID;
				if($current_cat_id == '//Номер категории'){
			?>
			//HTML шаблон
			<?php } 
				else{
					if($current_cat_id == '//Номер категории'){
						?>
			//HTML шаблон
			<?php } 
				else{
					if($current_cat_id == '//Номер категории'){
						?>
			//HTML шаблон
			<?php
						}
					}
				}
			endwhile;
			?>
		<?php
			the_posts_pagination($args = array(
				'show_all'     => false, 
				'end_size'     => 1,    
				'mid_size'     => 1,     
				'prev_next'    => true,  
				'prev_text'    => __('« Previous'),
				'next_text'    => __('Next »'),
				'add_args'     => false,
				'add_fragment' => '',
				'screen_reader_text' => __( 'Posts navigation' ),
			));
		?>
		<?php
		else :
			get_template_part( 'template-parts/content', 'none' );
	endif;
?>