dedecms sqllist实现分页
来源:互联网 发布:js给json数组添加元素 编辑:程序博客网 时间:2024/04/30 04:20
OK,思路已经有了,接下来我们打开include/arc.listview.class.php这个文件来给它动个小手术吧!
找到:
if(!is_object($ctag))
{
$ctag = $this->dtp->GetTag("list");
}
这一段,在其后添加如下代码:
//add by Gump 2011-12-31 http://gump.me/
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;
}
}
}
//end
然后找到:
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")
)
);
}
这一段,在其后添加如下代码:
//add by Gump 2011-12-31 http://gump.me/
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
最后找到function GetArcList这个方法,在其后添加一个可以通过传入sql参数获取指定数据源的方法,代码如下:
//add by Gump 2011-12-31 http://gump.me/
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;
}
//end
总共就添加三段代码,每一段代码基本都参考它紧接着的上面那段原始代码,而无需改变它原来任何一个地方的代码,应该算是比较完美的手术了,接下来在模板文件中的使用方法就跟一开始思路中所提到的那样,分页标签依旧沿用原来的,调用范例:
?View Code HTML
{dede:listsql sql='select ID,post_title from wp_posts' pagesize='10'}
<li><a href="http://gump.me/[field:ID /].html">[field:post_title /]</a></li>
{/dede:listsql}
<!--分页-->
{dede:pagelist listsize='2' listitem='index pre pageno next end '/}
注:以上解决方案适用于dedecms5.6版本。
- dedecms sqllist实现分页
- dedecms实现图集内容自定义分页
- dedecms实现图集内容自定义分页
- DEDECMS模板实现{dedesql=}分页
- DEDECMS教程:首页实现分页的两种方法
- dedecms中英文分页
- dedecms 分页样式修改
- dedecms 分页标题
- DEDECMS用sql标签分页
- dedecms分页标题长度修改
- dedecms如何自定义分页样式
- Android SqlList的应用
- SQlList数据库基础
- DeDeCms的分页处理PHP函数
- dedecms独立模型分页功能的完善
- dedecms 列表页:分页横向排列解决办法
- DedeCMS arclist的分页使用教程
- Dedecms文章内容分页{dede:pagebre…
- 一个例子教会你 serialize序列化与unserialize反序列化
- UVa 417-Word Index
- Red5集成到Tomcat6.0下并进行新项目的开发配置
- linux排序去重比较
- GetTextMetrics与GetTextExtent的区别
- dedecms sqllist实现分页
- HTML学习笔记
- C#类中对字段、属性、方法的介绍
- C语言之详解#ifdef等宏及妙用
- 机器学习中的算法(2)-支持向量机(SVM)基础
- 再次发帖,已是两年之久!
- Java中匿名类的两种实现方式 .
- OOA OOD OOP
- 俄罗斯的数学太牛逼了,请看下面的文章