首页 经验方法内容详情

CMS搜索连接格式化代码

2023-01-16 巨蚂蚁目录

1、打开文件parseurl_control.class.php 大概58行插入代码

//搜索URL if(substr($uri,0,7)=='search/'){ $_GET['control']='search'; $_GET['action']='index'; if(substr($uri,-1)!='/'){ $uri.='/'; } $newurl=substr($uri,7,-1); $u_arr_page=explode('/',$newurl); if(isset($u_arr_page[1])){ $_GET['page']=(int)$u_arr_page[1]; $_GET['keyword']=$u_arr_page[0]; } $u_arr=explode('_',$u_arr_page[0]); $u_arr_count=count($u_arr); if($u_arr_count==1){ $_GET['mid']=2; $_GET['keyword']=$u_arr[0]; return; }elseif($u_arr_count==2){ $_GET['mid']=(int)$u_arr[0]; $_GET['keyword']=$u_arr[1]; return; } }

2、打开文件cms_content_model.class.php 大概130行插入代码

//标签链接格式化 publicfunctiontag_url(&$mid,&$name,$page=FALSE){ //hookcms_content_model_tag_url_before.php if(empty($_ENV['_config']['apps_parseurl'])){ $s=$page?'-page-{page}':''; return$this->cfg['webdir'].'index.php?tag--mid-'.$mid.'-name-'.urlencode($name).$s.$_ENV['_config']['url_suffix']; }else{ return$this->cfg['webdir'].$this->cfg['link_tag_pre'].$mid.'_'.urlencode($name).($page?'_{page}':'').$this->cfg['link_tag_end']; } }

3、更新缓存即可

4、前端使用方法

window._cms={ uri:"{$cfg[weburl]}", uid:"{$_uid}", parseurl:"{$_parseurl}" }; main.js代码: $("#search_form,#search_form2").submit(function(){ varkeyword=$(this).find("[name='keyword']").val(); if(_cms.parseurl==1){ window.location.href=_cms.uri+"search/"+encodeURIComponent(keyword); }else{ window.location.href=_cms.uri+"index.php?search--keyword-"+encodeURIComponent(keyword); } returnfalse; });