Php Wordpress空搜索提交显示所有帖子/页面结果

Php Wordpress空搜索提交显示所有帖子/页面结果,php,wordpress,Php,Wordpress,我有一个Wordpress网站,有搜索表单。 但当我点击提交按钮而不在搜索栏中写任何东西时,网站就会给我所有的帖子和网页。 有没有什么方法可以让用户在没有在搜索字段中写入任何内容的情况下单击submit按钮时,收到类似“搜索字段为空-再次搜索”的消息 header.php-这是我使用get\u search\u form()从另一个页面获取搜索表单的地方 <!DOCTYPE html> <html <?php language_attributes(); ?>

我有一个Wordpress网站,有搜索表单。 但当我点击提交按钮而不在搜索栏中写任何东西时,网站就会给我所有的帖子和网页。 有没有什么方法可以让用户在没有在搜索字段中写入任何内容的情况下单击submit按钮时,收到类似“搜索字段为空-再次搜索”的消息

header.php-这是我使用get\u search\u form()从另一个页面获取搜索表单的地方

    <!DOCTYPE html>
<html <?php language_attributes(); ?>>
    <head>
        <meta charset="<?php bloginfo('charset'); ?>">
        <meta name="viewport" content="width=device-width">
        <title><?php bloginfo('name'); ?></title>
        <?php wp_head(); ?>
    </head>

<body <?php body_class(); ?>>



    <!-- site-header -->
    <header class="site-header">

        <div class="header-container">
            <nav class="site-nav">



                <h1 class ="head-title">Title</h1>

                    <!-- hd-search -->
                <div class="hd-search">
                    <?php get_search_form(); ?>
                </div><!-- /hd-search -->

                <?php

                $args = array(
                    'theme_location' => 'primary'
                );

                ?>

                <?php wp_nav_menu(  $args ); ?>
            </nav>
        </div>

    </header><!-- /site-header -->

    <div class="container">

 <form role="search" method="get" id="searchform" action="<?php echo   home_url( '/' ); ?>">
<div><label class="screen-reader-text" for="s">Search for:</label>
    <input type="text" value="" name="s" id="s" placeholder="<?php the_search_query(); ?>" />
    <input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
<?php

get_header();

if (have_posts()) : ?>

    <h2>Search results for: <?php the_search_query(); ?></h2>

    <?php
    while (have_posts()) : the_post(); ?>

    <article class="post <?php if ( has_post_thumbnail() ) { ?>has-thumbnail    <?php } ?>">

    <!-- post-thumbnail -->
    <div class="post-thumbnail">
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('small-thumbnail'); ?></a>
    </div><!-- /post-thumbnail -->



    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

    <p class="post-info"><?php the_time('F j, Y g:i a'); ?> | by <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>"><?php the_author(); ?></a> | Posted in

        <?php

        $categories = get_the_category();
        $separator = ", ";
        $output = '';

        if ($categories) {

            foreach ($categories as $category) {

                $output .= '<a href="' . get_category_link($category->term_id) . '">' . $category->cat_name . '</a>'  . $separator;

            }

            echo trim($output, $separator);

        }

        ?>

        </p>



        <?php the_excerpt(); ?>


    </article>

    <?php endwhile;

    else :
        echo '<p>No content found</p>';

    endif;

get_footer();

**strong text**?>