在使用织梦DedeCms做小说站、图片站、影视站类型网站的时候,往往需要使用多个栏目来区分内容类型。
以小说站为例,一个栏目就是一部小说,栏目内发布文章是小说的各个章节,当栏目已经存在很多的时候,就需要用到分页,但是织梦官方别没有提供栏目分页的代码,本文教程课轻松实现栏目分页,也可扩展其他分页,例如会员分页,自定义表单分页等
打开 /include/arc.listview.class.php 有三处需要修改,找到 大概在248行
$ctag = $this->dtp->GetTag("page");
在它下面加入
if(!is_object($ctag))
{
$ctag = $this->dtp->GetTag("listsql");if(is_object($ctag))
{$this->addSql = " WHERE ishidden<>1 ";if($cfg_list_son=='N')
{if($this->CrossID=='') $this->addSql .= " AND (id='".$this->TypeID."') ";else $this->addSql .= " AND (id in({$this->CrossID},{$this->TypeID})) ";
}else
{
$sonids = GetSonIds($this->TypeID,$this->Fields['channeltype'],0);if(!preg_match("/,/", $sonids)) {$this->addSql .= " AND id = '$sonids' ";
}else {$this->addSql .= " AND id IN($sonids) ";
}
}
$sql = $ctag->GetAtt("sql");
$sql = preg_replace("/SELECT(.*?)FROM/is", " SELECT count(*) as dd FROM ", $sql);
$sql = preg_replace("/ORDER(.*?)SC/is", "", $sql);
$sql = $sql.$this->addSql;
$row = $this->dsql->GetOne($sql);if(is_array($row))
{$this->TotalResult = $row['dd'];
}else
{$this->TotalResult = 0;
}
}
}
找到
else if($ctag->GetName()=="pagelist")
在它上面加入
else if($ctag->GetName()=="listsql")
{
$limitstart = ($this->PageNo-1) * $this->PageSize;
$row = $this->PageSize; if(trim($ctag->GetInnerText())=="")
{
$InnerText = GetSysTemplets("list_fulllist.htm");
} else
{
$InnerText = trim($ctag->GetInnerText());
} $this->dtp->Assign($tagid, $this->GetSqlList(
$limitstart,
$row,
$ctag->GetAtt("sql"),
$InnerText
));
}
找到
function GetPageListST
在它上面加入
function GetSqlList($limitstart = 0, $row = 10, $sql = '', $innertext){ global $cfg_list_son;
$innertext = trim($innertext); if ($innertext == '')
{
$innertext = GetSysTemplets('list_fulllist.htm');
}
$limitStr = " LIMIT {$limitstart},{$row}";
$sql = $sql.$this->addSql.$limitStr; $this->dsql->SetQuery($sql); $this->dsql->Execute('al');
$t2 = ExecTime();
$sqllist = ''; $this->dtp2->LoadSource($innertext);
$GLOBALS['autoindex'] = 0;
while($row = $this->dsql->GetArray("al"))
{
$row['typeurl'] = GetTypeUrl($row['typeid'],MfTypedir($row['typedir']),$row['isdefault'],$row['defaultname'],
$row['ispart'],$row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);
$row['typelink'] = GetOneTypeUrlA($row);
$GLOBALS['autoindex']++; if(is_array($this->dtp2->CTags))
{ foreach($this->dtp2->CTags as $k=>$ctag)
{ if($ctag->GetName()=='array')
{
$this->dtp2->Assign($k,$row);
} else
{ if(isset($row[$ctag->GetName()]))
{ $this->dtp2->Assign($k,$row[$ctag->GetName()]);
} else
{ $this->dtp2->Assign($k,'');
}
}
}
}
$sqllist .= $this->dtp2->GetResult();
}
$t3 = ExecTime();
$this->dsql->FreeResult('al'); return $sqllist;
}
栏目模板标签写法
<h2>栏目列表</h2><ul>
{dede:listsql sql="select * from dede_arctype" pagesize="10"}<li>
<a href="[field:typelink/]">[field:typename/]</a>
<p>栏目描述:[field:description/]...</p>
</li>
{/dede:listsql}</ul><h2>栏目分页条</h2><ul class="pagelist">
{dede:pagelist listitem="info,index,end,pre,next,pageno,option" listsize="5"/}</ul>
pagesize="10" 每页显示10个栏目
[field:typelink/] 栏目链接
[field:typename/] 栏目名称
[field:其他字段/] 栏目其他自定义字段都可以直接调用