Md Mehedi Hasan

get_search_form | get_search_query | Search.php | Searchform.php

Search form location:

<div class="containter">
    <div class="row">
        <div class="col-md-12 text-center">
            <?php
            echo get_search_form();
            ?>
        </div>
    </div>
</div>

search.php

<?php

if (!have_posts()) {
?>
    <h4 class="text-center">
        <?php _e('No result found', 'alpha'); ?>
    </h4>
<?php
}
while (have_posts()) {
    the_post(); ?>

    <div <?php post_class(); ?>>>
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <a href="<?php the_permalink(); ?>">
                        <h2 class="post-title"><?php the_title(); ?></h2>
                    </a>
                </div>

            </div>
            <div class="row">
                <div class="col-md-4">
                    <p>
                        <strong><?php the_author_posts_link(); ?></strong><br />
                        <?php the_date(); ?>
                    </p>

                    <?php the_tags('<ul class="list-unstyled"><li>', '</li><li>', '</li></ul>'); ?>
                </div>
                <div class="col-md-8">
                    <?php
                    if (has_post_thumbnail()) {
                        the_post_thumbnail("large", array("class" => "img-fluid"));
                    }

                    the_excerpt();
                    ?>


                </div>
            </div>
        </div>
    </div>
<?php

}
?>

functions.php

function alpha_bootstraping() {
    add_theme_support( 'html5', array( 'search-form' ) );
}
add_action( 'after_setup_theme', 'alpha_bootstraping' );

searchform.php

<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
    <label>
        <span class="screen-reader-text"><?php echo _x( 'Search for:', 'alpha' ) ?></span>
        <input type="search" class="search-field"
            placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder' ) ?>"
            value="<?php echo get_search_query() ?>" name="s"
            title="<?php echo esc_attr_x( 'Search for:', 'alpha' ) ?>" />
    </label>
    <input type="submit" class="search-submit"
        value="<?php echo esc_attr_x( 'Search', 'submit button' ) ?>" />
</form>