You can use part of the template called post-search.php and you can use it in the search.php file, for example
get_template_part( 'post' , 'search')
but you need to create a php file inside the theme folder and name it post-search.php , and inside this file just set the WordPress loop ie
<?php while (have_posts()) : the_post(); ?> <div class="post-entry clearfix"> <div class="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> </div> <?php endwhile; ?>
and your .php search might be something like this
<?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> <?php get_sidebar(' '); ?> </div> <?php get_footer(' '); ?>
This is just an example, change the div / h2 id / class names to suit your css theme.
Note. . I am currently using this approach on one of my sites, and I have one file named "post-entry.php" in my theme folder and in every template file (index .php, search.php, etc. ) I just use this file, calling
<?php get_template_part( 'post' , 'entry') ?>
source share