前言概述
帝国CMS搜索页,搜索不同的数据表调用不同的搜索模板方法。
==========================================
这两天在写个游戏站的模板,都做完了,想着有应用数据表跟资讯数据表,搜索页应该需要两个才行。
因为搜索应用跟资讯出来的列表页面肯定样式是不一样的。
==========================================
方法一 :
搜索模版代码参考:
<div class="searchBox">
<form action="/e/search/index.php" name="searchform" method="post" target="_blank" id="searchform" target="_blank">
<input type="hidden" name="tbname" value="app">
<input type="hidden" name="tempid" value="1">
<select id="soselect" name="tbname" onchange="if(this.value==='app'){document.searchform.tempid.value=1;}else{document.searchform.tempid.value=2;}">
<option value="app">APP</option>
<option value="news">资讯</option>
</select>
<input type="text" name="keyboard" id="keyboard" placeholder="">
<input type="hidden" name="show" value="title,newstext">
<button class="uk-position-center-right"><i class="icon"></i></button>
</form>
</div>
效果图展示 :
在这里遇到一个小问题,就是在搜索的过程中,第一次用文章表搜,第二次用新闻表搜,调用的是不同的搜索模板,可是每次搜完第一次,再搜第二次的时候列表页模板就显示的不正常,
比如搜完应用,再搜索资讯文章的时候,文章的列表会显示错位,查看源码发现是展示的应用搜索模板代码,刷新后台缓存才正常显示资讯搜索模板。
经过一下午的研究终于发现,需要在系统 – 系统设置 – 系统参数设置 – 信息设置中把动态列表变量缓存跟动态内容页变量缓存设置为0,即不缓存,问题完美解决。
方法二:
将以下内容替换到/e/search/result/index.php
<?php
require('../../class/connect.php');
require('../../class/db_sql.php');
require('../../class/functions.php');
require('../../class/t_functions.php');
require('../../data/dbcache/class.php');
require "../".LoadLang("pub/fun.php");
$editor=1;
eCheckCloseMods('search');//关闭模块
$link=db_connect();
$empire=new mysqlquery();
$getvar=$_GET['getvar'];
if(empty($getvar))
{
$getfrom="history.go(-1)";
}
else
{
$getfrom="../../../search/";
}
//搜索结果
$searchid=(int)$_GET['searchid'];
if(empty($searchid))
{
printerror("SearchNotRecord",$getfrom,1);
}
$search_r=$empire->fetch1("select searchid,keyboard,result_num,orderby,myorder,tbname,tempid,andsql,trueclassid from {$dbtbpre}enewssearch where searchid='$searchid'");
if(empty($search_r['searchid'])||InfoIsInTable($search_r[tbname]))
{
printerror("SearchNotRecord",$getfrom,1);
}
$page=(int)$_GET['page'];
$page=RepPIntvar($page);
$start=0;
$page_line=$public_r['search_pagenum'];//每页显示链接数
$line=$public_r['search_num'];//每页显示记录数
$offset=$page*$line;//总偏移量
$search="&searchid=".$searchid;
$myorder=$search_r[orderby];
if(empty($search_r[myorder]))
{
$myorder.=" desc";
}
$add=stripSlashes($search_r['andsql']);
$num=$search_r[result_num];
if(strstr($add,"\\"))
{
exit();
}
$query="select * from {$dbtbpre}ecms_".$search_r[tbname].($add?' where '.substr($add,5):'');
$query.=" order by ".$myorder." limit $offset,$line";
$sql=$empire->query($query);
$listpage=page1($num,$line,$page_line,$start,$page,$search);
//取得模板
if($search_r['tempid'])
{
$tempr=$empire->fetch1("select temptext,subnews,listvar,rownum,showdate,modid,subtitle,docode from ".GetTemptb("enewssearchtemp")." where tempid='".$search_r['tempid']."' limit 1");
}
elseif(empty($class_r[$search_r[trueclassid]][searchtempid]))
{
$tempr=$empire->fetch1("select temptext,subnews,listvar,rownum,showdate,modid,subtitle,docode from ".GetTemptb("enewssearchtemp")." where isdefault=1 limit 1");
}
else
{
$tempr=$empire->fetch1("select temptext,subnews,listvar,rownum,showdate,modid,subtitle,docode from ".GetTemptb("enewssearchtemp")." where tempid='".$class_r[$search_r[trueclassid]][searchtempid]."' limit 1");
}
$have_class=1;
//页面支持标签
$tempr[temptext]=DtNewsBq('list'.$search_r['tempid'],$tempr[temptext],0);
//替换公共模板变量
$listtemp=$tempr[temptext];
if($public_r['searchtempvar'])
{
$listtemp=ReplaceTempvar($listtemp);
}
$search_r[keyboard]=ehtmlspecialchars($search_r[keyboard]);
$listtemp=str_replace("[!--show.page--]",$listpage,$listtemp);
$listtemp=str_replace("[!--keyboard--]",$search_r[keyboard],$listtemp);
$listtemp=str_replace("[!--ecms.num--]",$num,$listtemp);
$url="<a href='".ReturnSiteIndexUrl()."'>".$fun_r['index']."</a> > ".$fun_r['adsearch'];
$pagetitle=$fun_r['adsearch']." ".$search_r[keyboard];
$listtemp=ReplaceSvars($listtemp,$url,0,$pagetitle,$pagetitle,$pagetitle,$add,0);
$rownum=$tempr[rownum];
if(empty($rownum))
{
$rownum=1;
}
$formatdate=$tempr[showdate];
$subnews=$tempr[subnews];
$subtitle=$tempr[subtitle];
$docode=$tempr[docode];
$modid=$tempr[modid];
$listvar=str_replace('[!--news.url--]',$public_r[newsurl],$tempr[listvar]);
//字段
$ret_r=ReturnReplaceListF($tempr[modid]);
//取得列表模板
$list_exp="[!--empirenews.listtemp--]";
$list_r=explode($list_exp,$listtemp);
$listtext=$list_r[1];
$no=$offset+1;
$changerow=1;
while($r=$empire->fetch($sql))
{
//替换列表变量
$r[title]=str_replace($search_r[keyboard],"<font color='red'>$search_r[keyboard]</font>",$r[title]); //搜索关键字加色高亮显示
$repvar=ReplaceListVars($no,$listvar,$subnews,$subtitle,$formatdate,$url,$have_class,$r,$ret_r,$docode);
$listtext=str_replace("<!--list.var".$changerow."-->",$repvar,$listtext);
$changerow+=1;
//超过行数
if($changerow>$rownum)
{
$changerow=1;
$string.=$listtext;
$listtext=$list_r[1];
}
$no++;
}
db_close();
$empire=null;
//多余数据
if($changerow<=$rownum&&$listtext<>$list_r[1])
{
$string.=$listtext;
}
$string=$list_r[0].$string.$list_r[2];
echo stripSlashes($string);
?>
网站中用到两个甚至多个搜索模板,在搜索代码中除了会设置指定的模板id以外,还需要更改以下内容,目的就为了解决缓存问题,比如说,用户可能是在搜索“应用”图文列表后,再去搜“资讯”,搜索列表显示的还是之前“应用”的搜索模板。注释:提醒大家一定要先备份哟!
- 『零氪源码』—— “一个优质的源码资源平台!”
- 本文地址:https://www.lynkcode.com/pages/lynk/jiaocheng/guide-notes/288.html
- 本文标题:帝国CMS搜索页,搜索不同的数据表调用不同的搜索模板方法
- 本文版权:零氪源码 (www.lynkcode.com) » 所发布的内容,如无特别说明,转载请注明本文地址,如有侵权请联系我们!