有时候我们想对指定搜索关键词进行更好的结果显示聚合,可能会需要把搜索结果页跳转到指定的归档页面,那么如何实现呢?
下面来写出主要的方法代码:
- function search_jump9 a v 7 H /( $Z 2 L a x w P O 0query, $error = trI 5 , Due ) {
- if (iC I 8 0 \ } Ws_search() && !is_admin()) {
- $jump = 0;$url = '';
- $epd_game_search = get_optix s p r ! R s m gon('epd_game_search');
- if($epd_game_3 L u ? G & Rsearch){
- $cnt0 h G N . = . H = count($epd_game_search['buy']e T 4 V);
- for($i=0; $i<$cnt;$i++){
- if( strpos($query->quP 7 X 4 a W ]ery 8 q s X1;'s'], $epd_game_search['buy'][$i]) !== false ){
- $jump = 1;
- $url = $epd_game_search['get'][$i];
- break;
- }
- }
- }
- if($jump==1){
- $queryv d H->is_seH u n \ 0 ( b Jarch = false;
- $query->query_vars['s'] = false;
- $query->query['s'] = fals, o 9 ` 0 Ee;
- if ( $error == true ){
- //$query->is_404 = true;
- echo '&lO ( M ( u { W ot;HTML><script>location.href="'.$url.'";</script></hd Y x * ` m Gtml>';
- exit;
- }
- }Y m % 9 f
- }
- }
- add_action( 'parse_query', 'search_jump' );
代码里的$epd_game_search 是一个数组,你预先设定好关键词以及对应跳转地址即可。