不如为你的搜索页面制作一个新模板,并将搜索表单放在其中。像这样:
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-12">
<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( \'/\' ) ); ?>">
<label>
<span class="screen-reader-text"><?php echo _x( \'Search for:\', \'label\', \'yourTheme\' ); ?></span>
<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( \'Search …\', \'placeholder\', \'yourTheme\' ); ?>" value="<?php echo get_search_query(); ?>" name="s" />
</label>
<button type="submit" class="search-submit"><span class="screen-reader-text"><?php echo _x( \'Search\', \'submit button\', \'yourTheme\' ); ?></span></button>
</form>
</div>
<div class="col-md-6 col-sm-12">
<?php
while ( have_posts() ) : the_post();
get_template_part( \'template-parts/content\', \'page\' );
if ( comments_open() || get_comments_number() ) {
comments_template();
}
endwhile;
?>
</div>
</div>
</div>