WordPress.org

Codex

Function Reference/it:get search form

Contents

Descrizione

Mostra il form di ricerca usando il file del tema searchform.php.

Utilizzo

<?php get_search_form(); ?>

Parametri

Questa funzione non accetta nessun parametro.

Esempi

Se tu non hai un searchform.php nel tuo tema, WordPress mostrerà il suo form di ricerca standard:

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

Mentre, nel caso in cui tu avessi il file searchform.php nel tuo tema, questo sarà usato al posto di quello standard. Ricorda che il tuo form di ricerca deve essere impostato con metodo a GET verso la pagina iniziale del tuo blog. L'attributo name del campo di testo deve essere impostato con s e dovresti sempre includere una label come nell'esempio qui sotto.

Example of a custom searchform.php:

<form action="/" method="get">
    <fieldset>
        <label for="search">Cerca in <?php echo home_url( '/' ); ?></label>
        <input type="text" name="s" id="search" value="<?php the_search_query(); ?>" />
        <input type="image" alt="Cerca" src="<?php bloginfo( 'template_url' ); ?>/images/search.png" />
    </fieldset>
</form>

Un'ultima opzione è quella di scrivere una funzione personalizzata (nel tuo file functions.php) e agganciarla al filtro get_search_form.

function my_search_form( $form ) {

    $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
    <div><label class="screen-reader-text" for="s">' . __('Cerca:') . '</label>
    <input type="text" value="' . get_search_query() . '" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="'. esc_attr__('Cerca') .'" />
    </div>
    </form>';

    return $form;
}

add_filter( 'get_search_form', 'my_search_form' );

Note

Change Log

Sorgenti

get_search_form() è situato in wp-includes/general-template.php.

Simili

Include Tags: get_header(), get_footer(), get_sidebar(), get_template_part(), get_search_form(), comments_template()

See also index of Function Reference and index of Template Tags.