Вы можете использовать часть шаблона с именем post-search.php
и использовать ее в вашем файле search.php, например
get_template_part( 'post' , 'search')
но вы должны создать php-файл внутри папки вашей темы и назвать его post-search.php
, а внутри этого файла просто поместить цикл WordPress, т.е.
<?php while (have_posts()) : the_post(); ?>
<div class="post-entry clearfix"> <!-- Main wrapper -->
<div class="post-entry-content"> <!-- Post-entry-content -->
<h2><a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<div class="post-entry-date">Posted on <?php the_time('F Y') ?> with <?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></div>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(' ') ?>" class="post-entry-read-more" title="<?php the_title(); ?>">Read More ?</a>
</div><!-- END of post-entry-content -->
</div><!--End of main wrapper -->
<?php endwhile; ?>
и ваш search.php может выглядеть примерно так
<?php get_header(' '); ?>
<div id="post-wrap">
<div id="post-content">
<?php if (have_posts()) : ?>
<?php get_template_part( 'post' , 'search') ?> // This will load/include the file post-search.php and result will be displayed as formatted in this file
<?php else : ?>
<p>Sorry, it does not exist !</p>
<?php endif; ?>
</div><!-- END post-conten -->
<?php get_sidebar(' '); ?>
</div><!-- END post-wrap -->
<?php get_footer(' '); ?>
Это всего лишь пример, измените имена div / h2 id / class в соответствии с вашей темой css.
Примечание: В настоящее время я использую этот подход на одном из моих сайтов, и у меня есть один файл с именем 'post-entry.php' в папке моей темы и в каждом файле моего шаблона (индекс. php, search.php и т. д.) Я просто использую этот файл, вызывая
<?php get_template_part( 'post' , 'entry') ?>