HTML代码中的表单如下所示:
<form method="get" id="searchform" action="<?php echo $_SERVER[\'PHP_SELF\']; ?>">
<label class="hidden" for="s"><?php _e(\'Search this site:\'); ?></label>
<input type="text" value="Search site" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" />
</form>
PHp在这个片段中没有被解析,所以我猜您没有包含PHp文件,只有普通的HTML。将搜索表单代码放入PHP文件中。
例如,您可以将这样的函数添加到functions.php
:
function t5_search_form( $args = array () )
{
$defaults = array (
\'form_id\' => \'searchform\',
\'name\' => \'s\',
\'charset\' => get_bloginfo( \'charset\' ),
\'label\' => esc_attr__( \'Search\', \'t5_theme\' ),
\'action\' => site_url(),
\'value\' => esc_attr(
apply_filters( \'the_search_query\', get_search_query( FALSE ) )
),
\'submit\' => esc_attr__( \'Search\', \'t5_theme\' ),
\'template\' => \'
<form role="search" id="%1$s" accept-charset="%2$s" action="%8$s">
<label for="%3$s">%4$s</label>
<input type="search" name="%3$s" id="%3$s" value="%5$s" aria-required="true" required%6$s>
<input type="submit" value="%7$s">
</form>\',
\'print\' => TRUE
);
$options = array_merge( $defaults, $args );
$options = apply_filters( \'t5_searchform\', $options );
extract( $options );
$autofocus = ( is_search() and 0 === (int) $GLOBALS["wp_query"]->found_posts )
? \' autofocus\' : \'\';
$form = sprintf(
$template,
$form_id,
$charset,
$name,
$label,
$value,
$autofocus,
$submit,
$action
);
$print and print $form;
return $form;
}
…并在需要时调用该函数
t5_search_form();
.
另外,不要使用$_SERVER[\'PHP_SELF\'];
, 使用echo home_url();
相反