Phpcms筛选搜索列表美化教程

Phpcms筛选搜索列表美化教程


  第一步:找到phpcms/modules/content/search.php,在最后头添加以下代码

public function test() { $grouplist = getcache('grouplist','member');
$_groupid = param::get_cookie('_groupid'); if(!$_groupid) $_groupid = 8; /*
if(!$grouplist[$_groupid]['allowsearch']) {
if ($_groupid==8) showmessage(L('guest_not_allowsearch'));
else showmessage(''); } */
if(!isset($_GET['catid'])) showmessage(L('missing_part_parameters'));
$catid = intval($_GET['catid']);
$siteids = getcache('category_content','commons');
$siteid = $siteids[$catid];
$this->categorys = getcache('category_content_'.$siteid,'commons');
if(!isset($this->categorys[$catid])) showmessage(L('missing_part_parameters'));
if(isset($_GET['info']['catid']) && $_GET['info']['catid']) {
$catid = intval($_GET['info']['catid']); } else {
$_GET['info']['catid'] = 0; }
$modelid = $this->categorys[$catid]['modelid'];
$modelid = intval($modelid);
if(!$modelid) showmessage(L('illegal_parameters')); //搜索隔断
$minrefreshtime = getcache('common','commons');
$minrefreshtime = intval($minrefreshtime['minrefreshtime']);
$minrefreshtime = 1;//$minrefreshtime ? $minrefreshtime : 5; /*
if(param::get_cookie('search_cookie') && param::get_cookie('search_cookie')>SYS_TIME-2) {
showmessage(L('search_minrefreshtime',array('min'=>$minrefreshtime)),'index.php?m=content&c=search&catid='.$catid,$minrefreshtime*1280);
} else { param::set_cookie('search_cookie',SYS_TIME+2); } */ //搜索隔断
$CATEGORYS = $this->categorys; //发生表单
pc_base::load_sys_class('form','',0);
$fields = getcache('model_field_'.$modelid,'model'); $forminfos = array();
$surl="index.php?m=content&c=search&"; $searchfields=array();
foreach ($fields as $field=>$r) { if($r['issearch']) {
$surl.= $r[field]."=".htmlspecialchars($_GET[$r[field]])."&" ;
$searchfields[]=$r['field']; } }
$surl.="catid=$catid&a=test&dosubmit=1"; $order = '';
$pointsorder=$surl.'&ord=1'; $idorder=$surl.'&ord=3';
switch($_GET['ord']) { case 1: $order=" a.points DESC";
$pointsorder=$surl.'&ord=2'; break; case 2:
$order=" a.points ASC"; $pointsorder=$surl.'&ord=1'; break;
case 3: $order=" a.id DESC "; $idorder=$surl.'&ord=3'; break;
case 4: $order=" a.id ASC "; $idorder=$surl.'&ord=4'; break;
default: $order=" a.id DESC "; break; }
foreach ($fields as $field=>$r) { if($r['issearch']) {
if($r['formtype']=='box') { $options = explode("\n",$r['options']);
$option=array(); foreach($options as $_k) { $v = explode("|",$_k);
$option[$v[1]] = $v[0]; } switch($r['boxtype']) {
case 'radio':
//$string = form::radio($option,$value,"name='info[$field]'");
if($_GET[$r[field]]) {
$tempstr=" <a href='http://down.chinaz.com/".preg_replace("/{$r[field]}=.*&/iUs","{$r[field]}=&",$surl)."'> 全部 </a>";
}else { $tempstr=" <b>全部</b>"; }
foreach($option as $tk=>$tv) {
if($_GET[$r[field]]==$tv && $tv) {
$tempstr.="<b>{$tv}</b>"; }else {
$tempstr.=" <a href='http://down.chinaz.com/".preg_replace("/{$r[field]}=.*&/iUs","{$r[field]}={$tv}&",$surl)."'>$tv</a> ";
} } $string=$tempstr; $r['form'] = $string;
$forminfos[$field] = $r; break; } } } }
//----------- $siteid = $this->categorys[$catid]['siteid'];
$siteurl = siteurl($siteid); $this->db->set_model($modelid);
$tablename = $this->db->table_name;
$page = max(intval($_GET['page']), 1);
$sql = "SELECT * FROM `{$tablename}` a,`{$tablename}_data` b WHERE a.id=b.id AND a.status=99";
$sql_count = "SELECT COUNT(*) AS num FROM `{$tablename}` a,`{$tablename}_data` b WHERE a.id=b.id AND a.status=99";
//结构搜索SQL $where = ''; $catid=$_GET['catid']; $_GET['catid']='';
foreach($_GET as $k=>$v) { if(in_array($k,$searchfields)) {
if($v ) { $where.=" AND a.{$k}='$v' "; } } }
$pagesize = 21; $offset = intval($pagesize*($page-1));
$sql_count .= $where; $this->db->query($sql_count);
$total = $this->db->fetch_array(); $total = $total[0]['num'];
if($total!=0) { $sql .= $where; $sql .= ' ORDER BY '.$order;
$sql .= " LIMIT $offset,$pagesize"; $this->db->query($sql);
$datas = $this->db->fetch_array();
$pages = pages($total, $page, $pagesize); } else { $datas = array();
$pages = ''; } $SEO = seo($siteid, $catid, $keywords);
include template('content','search_test'); }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/10076.html