首先找到 “include” 文件夹下的 arc.searchview.class.php 文件
已修改后的方法,可以直接调用 [field:global name=autoindex /]
/** * 获得文档列表 * * @access public * @param int $limitstart 限制开始 * @param int $row 行数 * @param int $col 列数 * @param int $titlelen 标题长度 * @param int $infolen 描述长度 * @param int $imgwidth 图片宽度 * @param int $imgheight 图片高度 * @param string $achanneltype 列表类型 * @param string $orderby 排列顺序 * @param string $innertext 底层模板 * @param string $tablewidth 表格宽度 * @return string */ function GetArcList($limitstart=0,$row=10,$col=1,$titlelen=30,$infolen=250, $imgwidth=120,$imgheight=90,$achanneltype="all",$orderby="default",$innertext="",$tablewidth="100") { global $cfg_sphinx_article; $GLOBALS['autoindex'] = 0; $typeid=$this->TypeID; if($row=='') $row = 10; if($limitstart=='') $limitstart = 0; if($titlelen=='') $titlelen = 30; if($infolen=='') $infolen = 250; if($imgwidth=='') $imgwidth = 120; if($imgheight='') $imgheight = 120; if($achanneltype=='') $achanneltype = '0'; $orderby = $orderby=='' ? 'default' : strtolower($orderby); $tablewidth = str_replace("%","",$tablewidth); if($tablewidth=='') $tablewidth=100; if($col=='') $col=1; $colWidth = ceil(100/$col); $tablewidth = $tablewidth."%"; $colWidth = $colWidth."%"; $innertext = trim($innertext); if($innertext=='') { $innertext = GetSysTemplets("search_list.htm"); } if ($cfg_sphinx_article == 'Y') { $ordersql = ''; if($this->ChannelType< 0 ||$this->ChannelTypeid< 0) { if($orderby=="id"){ $ordersql="@id desc"; }else{ $ordersql="@senddate desc"; } } else { if($orderby=="senddate") { $ordersql="@senddate desc"; } else if($orderby=="pubdate") { $ordersql="@pubdate desc"; } else if($orderby=="id") { $ordersql="@id desc"; } else { $ordersql="@sortrank desc"; } } $this->sphinx->SetLimits($limitstart, (int)$row, ($row>1000) ? $row : 1000); $res = array(); $res = AutoCharset($this->sphinx->Query($this->Keywords, 'mysql, delta'), 'utf-8', 'gbk'); foreach ($res['words'] as $k => $v) { $this->Keywords .= " $k"; } foreach($res['matches'] as $_v) { $aids[] = $_v['id']; } $aids = @implode(',', $aids); //搜索 $query = "SELECT arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule, act.namerule2,act.ispart,act.moresite,act.siteurl,act.sitepath FROM `#@__archives` arc LEFT JOIN `#@__arctype` act ON arc.typeid=act.id WHERE arc.id IN ($aids)"; } else { //排序方式 $ordersql = ''; if($this->ChannelType< 0 ||$this->ChannelTypeid< 0) { if($orderby=="id"){ $ordersql="ORDER BY arc.aid desc"; }else{ $ordersql="ORDER BY arc.senddate desc"; } } else { if($orderby=="senddate") { $ordersql=" ORDER BY arc.senddate desc"; } else if($orderby=="pubdate") { $ordersql=" ORDER BY arc.pubdate desc"; } else if($orderby=="id") { $ordersql=" ORDER BY arc.id desc"; } else { $ordersql=" ORDER BY arc.sortrank desc"; } } //搜索 $query = "SELECT arc.*,act.typedir,act.typename,act.isdefault,act.defaultname,act.namerule, act.namerule2,act.ispart,act.moresite,act.siteurl,act.sitepath FROM `{$this->AddTable}` arc LEFT JOIN `#@__arctype` act ON arc.typeid=act.id WHERE {$this->AddSql} $ordersql LIMIT $limitstart,$row"; } $this->dsql->SetQuery($query); $this->dsql->Execute("al"); $artlist = ""; if($col>1) { $artlist = "<table width='$tablewidth' border='0' cellspacing='0' cellpadding='0'>\r\n"; } $this->dtp2->LoadSource($innertext); for($i=0;$i<$row;$i++) { $GLOBALS['autoindex'] ++; if($col>1) { $artlist .= "<tr>\r\n"; } for($j=0;$j<$col;$j++) { if($col>1) { $artlist .= "<td width='$colWidth'>\r\n"; } if($row = $this->dsql->GetArray("al")) { if($this->ChannelType< 0 || $this->ChannelTypeid< 0) { $row["id"]=$row["aid"]; $row["ismake"]=empty($row["ismake"])? "" : $row["ismake"]; $row["filename"]=empty($row["filename"])? "" : $row["filename"]; $row["money"]=empty($row["money"])? "" : $row["money"]; $row["description"]=empty($row["description "])? "" : $row["description"]; $row["pubdate"]=empty($row["pubdate "])? $row["senddate"] : $row["pubdate"]; } //处理一些特殊字段 $row["arcurl"] = GetFileUrl($row["id"],$row["typeid"],$row["senddate"],$row["title"], $row["ismake"],$row["arcrank"],$row["namerule"],$row["typedir"],$row["money"],$row['filename'],$row["moresite"],$row["siteurl"],$row["sitepath"]); $row["description"] = $this->GetRedKeyWord(cn_substr($row["description"],$infolen)); $row["title"] = $this->GetRedKeyWord(cn_substr($row["title"],$titlelen)); $row["id"] = $row["id"]; if($row['litpic'] == '-' || $row['litpic'] == '') { $row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif'; } if(!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') { $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic']; } $row['picname'] = $row['litpic']; $row["typeurl"] = GetTypeUrl($row["typeid"],$row["typedir"],$row["isdefault"],$row["defaultname"],$row["ispart"],$row["namerule2"],$row["moresite"],$row["siteurl"],$row["sitepath"]); $row["info"] = $row["description"]; $row["filename"] = $row["arcurl"]; $row["stime"] = GetDateMK($row["pubdate"]); $row["textlink"] = "<a href='".$row["filename"]."'>".$row["title"]."</a>"; $row["typelink"] = "[<a href='".$row["typeurl"]."'>".$row["typename"]."</a>]"; $row["imglink"] = "<a href='".$row["filename"]."'><img src='".$row["picname"]."' border='0' width='$imgwidth' height='$imgheight'></a>"; $row["image"] = "<img src='".$row["picname"]."' border='0' width='$imgwidth' height='$imgheight'>"; $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl']; $row['memberurl'] = $GLOBALS['cfg_memberurl']; $row['templeturl'] = $GLOBALS['cfg_templeturl']; if(is_array($this->dtp2->CTags)) { foreach($this->dtp2->CTags as $k=>$ctag) { if($ctag->GetName()=='array') { //传递整个数组,在runphp模式中有特殊作用 $this->dtp2->Assign($k,$row); } else { if(isset($row[$ctag->GetName()])) { $this->dtp2->Assign($k,$row[$ctag->GetName()]); } else { $this->dtp2->Assign($k,''); } } } } $artlist .= $this->dtp2->GetResult(); }//if hasRow else { $artlist .= ""; } if($col>1) $artlist .= "</td>\r\n"; }//Loop Col if($col>1) { $artlist .= "</tr>\r\n"; } }//Loop Line if($col>1) { $artlist .= "</table>\r\n"; } $this->dsql->FreeResult("al"); return $artlist; }
在属性定义添加,例如在 global $cfg_sphinx_article; 下添加:
$GLOBALS['autoindex'] = 0;
在循环条数 for($i=0;$i<$row;$i++) 添加 :
$GLOBALS['autoindex'] ++;
在 search.htm 添加
[field:global name='autoindex'/]
<body> {dede:list} <li class="line[field:global name='autoindex'/]"><a target="_blank">[field:title/]</a></li> {/dede:list}