Phpcms筛选搜索列表美化教程

  • 时间:
  • 浏览:0
作者:lrjxgl hihi 来源:用户投稿 浏览: 2012-5-4 17:150:00 字号:大 中 小

[摘要]phpcms默认的选搜索列表不大美观,本文分享有一1个通过修改模板的辦法 来美化页面,辦法 如下:

  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*12150);

} 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]' id='$field'");

if($_GET[$r[field]]) {

$tempstr=" <a href='".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='".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'); }

  第二步:在模板中加入以下代码

{loop $forminfos $field $info}        {if $info[formtype]=='box'}

<li ><p ><span>{$info[name]}:</span>{$info[form]}</p></li>

{/if} {/loop}

  演示地址:http://www.chuizi123.com/index.php?m=yp&c=index&a=gongdi&catid=278 

sssss
Tags: Phpcms   Phpcms美化   筛选美化  
责任编辑:qjt198895