织梦用{dede:sql}标签实现分页的方法

打开网站根目录下include文件夹内的arc.listview.class.php文件``

找到代码:if(!is_object($ctag)) { $ctag = $this->dtp->GetTag("list");}

这一段,在其后添加如下代码:

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;
}
}
}
//结束

找到代码:
if($ctag->GetName()=="list")
{
$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->GetArcList(
$limitstart,
$row,
$ctag->GetAtt("col"),
$ctag->GetAtt("titlelen"),
$ctag->GetAtt("infolen"),
$ctag->GetAtt("imgwidth"),
$ctag->GetAtt("imgheight"),
$ctag->GetAtt("listtype"),
$ctag->GetAtt("orderby"),
$InnerText,
$ctag->GetAtt("tablewidth"),
$ismake,
$ctag->GetAtt("orderway")
)
);
}

 在上面代码后面添加如下代码:

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 GetArcList这个函数
在function GetArcList后添加一个可以通过传入sql参数获取指定数据源的方法,代码如下:

/**

* 通过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;
}
//结束

总共就添加三段代码,每一段代码基本都参考它紧接着的上面那段原始代码,而无需改变它原来任何一个地方的代码,调用范例:

{dede:listsql sql='select ID,post_title from wp_posts' pagesize='10'} 
<li><a href="[field:ID/].html">[field:post_title/]</a></li>
 {/dede:listsql} 

<!--分页-->
 {dede:pagelist listsize='2' listitem='index pre pageno next end '/}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值