嗨,大家好,我是新来的,我正在尝试创建一个搜索表单,但是我的函数php文件似乎有问题。我实际上知道问题出在我的“ if”语句中,但是我不知道是否还有其他选择可以使它起作用。这是代码:
function my_search_form( $form ) {
$form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
<input type="text" name="s" id="search" align="center" size="30" value="' . get_searchform() . '" onfocus="if(this.value == . 'search & hit enter' . ) { this.value = . '' . ; }" onblur="if(this.value == . '' . ) {this.value = . 'search & hit enter' . ; }" />
<input type="hidden" value="post" name="post_type" id="post_type" />
</form>';
return $form;
}
add_filter( 'get_search_form', 'my_search_form' );
search & hit enter
这部分是无效的代码,需要转义
function my_search_form( $form ) {
$form = '
<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
<input type="text" name="s" id="search" align="center" size="30" value="' . get_searchform() . '" onfocus="if(this.value == \'search & hit enter\') { this.value = \'\'; }" onblur="if(this.value == \'\') {this.value =\'search & hit enter\'; }" />
<input type="hidden" value="post" name="post_type" id="post_type" />
</form>';
return $form;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句