2014-10-21 59 views
1

我的wordpress主题中有一个搜索表单。我想在搜索结果中使用自定义网址。表单操作 - 自定义网址

我的源代码:

<form method="get" id="searchform" action="<?php echo esc_url(home_url('/')); ?>"> 
<input type="text" name="s" id="s" onblur="if (value =='') {value = 'Search'}" onfocus="if (value == 'Search') {value =''}" value="Search" /> 
<input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e('', 'themevb'); ?>" /> 
</form> 

我的实际搜索网址:

http://www.example.com/?s=keyword&submit= 

我需要这个网址:

http://www.example.com/web/keyword 

回答

0

简单的解决方案,排队这个脚本,或者只是把下面搜索表单,它将导航到自定义搜索页面。

<script> 
jQuery(function($){ 
    $('#searchform').on('submit', function() { 
     window.location = "http://www.example.com/web/" + encodeURIComponent($(this).find('#s').val()); 
     return false; 
    }); 
}); 
</script> 

添加自定义重写规则,记得通过访问管理部分的settings->permalinks标签刷新规则。

add_rewrite_rule('web/(.+?)/?$','index.php?s=$matches[1]');