WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] SEARCH BAR (5 posts)

  1. themusicvacuum
    Member
    Posted 2 years ago #

    I want to add a search bar to JUST ONE page.

    <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
    <input type="text" onfocus="if(this.value=='Search here') this.value='';" onblur="if(this.value=='') this.value='Search here';" value="Search here" name="s" id="s" />
    </form>

    that is the search form.php.

    If i put it in the page.php template it will appear on all pages.

    Help!?

    Thanks so much.

  2. Rab
    Member
    Posted 2 years ago #

    You can use WordPress Conditional Tags. For example,

    is_page( 42 )
    When Page 42 (ID) is being displayed.

  3. themusicvacuum
    Member
    Posted 2 years ago #

    Thanks Rab!

    Where abouts would I use these tags? For example, if this is my code...

    <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
    <input type="text" onfocus="if(this.value=='Search here') this.value='';" onblur="if(this.value=='') this.value='Search here';" value="Search here" name="s" id="s" />
    </form>

    How would I incorporate my conditional tag into that?

    Sorry but there seems to be very little in way of explanation on this.

    Thanks so much.!

  4. Rab
    Member
    Posted 2 years ago #

    You will need to add it to page.php where ever you were going to before. If you were using it on page ID 42 only you would put in something like the code below. Just change the 42 value to whatever page ID.

    <?php if(is_page( '42' )) { ?>
    	<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
    	<input type="text" onfocus="if(this.value=='Search here') this.value='';" onblur="if(this.value=='') this.value='Search here';" value="Search here" name="s" id="s" />
    	</form>
    <?php }  ?>
  5. themusicvacuum
    Member
    Posted 2 years ago #

    magic Rab thanks a million.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags