织梦模板用{dede:sql}标签如何实现分页
未知
2023-11-21 10:58:57
0次
打开include/arc.listview.class.php这个文件
1,找到 if(!is_object($ctag))
{
$ctag = $this->dtp->GetTag("list");
}
//dede:sql分页设置
if(!is_object($ctag))
{
$ctag = $this->dtp->GetTag("listsql");
if (is_object($ctag))
{
$cquery = $ctag->GetAtt("sql");
$cquery = preg_replace("/SELECT(.*?)FROM/is", " SELECT count(*) as dd FROM ", $cquery);
$cquery = preg_replace("/ORDER(.*?)SC/is", "", $cquery);
$row = $this->dsql->GetOne($cquery);
if(is_array($row))
{
$this->TotalResult = $row['dd'];
}
else
{
$this->TotalResult = 0;
}
}
}
2,找到 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
)
);
}
//end
3,找到 ‘获取静态的分页列表’,在这个函数后面添加
/**
* 通过listsql标签中sql属性传入的参数来获得一个单列的文档列表
* */
function GetSqlList($limitstart = 0, $row = 10, $sql = '', $innertext){
global $cfg_list_son;
$innertext = trim($innertext);
if ($innertext == '') {
$innertext = GetSysTemplets('list_fulllist.htm');
}
//处理SQL语句
$limitStr = " LIMIT {$limitstart},{$row}";
$this->dsql->SetQuery($sql . $limitStr);
$this->dsql->Execute('al');
$t2 = ExecTime();
//echo $t2-$t1;
$sqllist = '';
$this->dtp2->LoadSource($innertext);
$GLOBALS['autoindex'] = 0;
//获取字段
while($row = $this->dsql->GetArray("al")) {
$GLOBALS['autoindex']++;
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,'');
}
}
}
}
$sqllist .= $this->dtp2->GetResult();
}//while
$t3 = ExecTime();
//echo ($t3-$t2);
$this->dsql->FreeResult('al');
return $sqllist;
}
html页面使用
{dede:listsql sql="select * from dede_archives arc LEFT JOIN dede_addonarticle adds ON adds.typeid=arc.typeid where adds.yunlink <>''" pagesize='10'}
<div class="rowlist">
<div class="item layui-col-lg3">
<a href="/plus/view.php?aid=[field:id/]"><img src="[field:litpic/]" style="width: 208px;height: 132px;"></a>
</div>
</div>
{/dede:listsql}
<div class="layui-box layui-laypage layui-laypage-default">
{dede:pagelist listitem="info,index,end,pre,next,pageno,option" listsize="5"/}
</div>
相关内容
MySQL变量类型与用途
MySQL支持多种数据类型,包括数值、字符串、日期和时间等类型,以...
2024-11-20 20:23:37
MySQL变量类型列表
MySQL变量类型包括数值、字符串、日期和时间等类型,用于存储不同...
2024-11-20 19:46:45
MySQL变量数据类型介绍
MySQL支持多种数据类型,包括数值、字符串、日期时间及枚举和集合...
2024-11-20 19:23:39
MySQL变量定义与初始化
MySQL变量分为系统变量和用户定义变量,用于存储数据和配置参数。...
2024-11-20 19:00:42