最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to make a search button that will search my website?

programmeradmin2浏览0评论

I want to make a search button that search only within my website.

  1. Do I need external PHP or PERL script?
  2. Can it done by JavaScript?
  3. Or simply by HTML.

I tried to create a form using HTML:

<form>
    <input type="search" name="banner_search" class="banner-text-box" >
    <input type="submit" name="" value="SEARCH" class="banner-text-btn">
</form>

I want to make a search button that search only within my website.

  1. Do I need external PHP or PERL script?
  2. Can it done by JavaScript?
  3. Or simply by HTML.

I tried to create a form using HTML:

<form>
    <input type="search" name="banner_search" class="banner-text-box" >
    <input type="submit" name="" value="SEARCH" class="banner-text-btn">
</form>
Share Improve this question edited Oct 17, 2016 at 6:37 Dave Romsey 17.9k11 gold badges56 silver badges70 bronze badges asked Oct 17, 2016 at 6:12 Govind JangidGovind Jangid 311 silver badge6 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

You can use WordPress's internal search by calling the get_search_form() function:

<?php get_search_form(); ?>

get_search_form() will use a default HTML form, but you can create your own custom form by adding a searchform.php file to your theme.

You can add this HTML form to your page

<form role="search" method="get" id="searchform" class="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    <div>
        <label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label>
        <input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" class="banner-text-box" />
        <input type="submit" id="searchsubmit" value="<?php echo esc_attr_x( 'Search', 'submit button' ); ?>" class="banner-text-btn"/>
    </div>
</form>

Refrence:

  • Default HTML Form
发布评论

评论列表(0)

  1. 暂无评论