国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > 織夢DEDE > 正文

dede:sql實現分頁,織夢sql實現分頁的辦法

2024-07-12 08:26:06
字體:
來源:轉載
供稿:網友
文章介紹

思路是把dede:list標簽進行改造, 列表頁專用標簽的工作原理大致是先通過欄目變量id獲取到對應的數據源再呈現到頁面上來,那么 就可以讓它不僅僅通過欄目變量id還可以通過指定的sql語句來獲取數據源 可以另外嵌入一個類似{dede:listsql sql='select * from wp_posts' pagesize='10'}的標簽來使用。 

打開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這個方法,在其后添加一個可以通過傳入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="http://www.genban.org/[field:ID /].html">[field:post_title /]</a></li>
{/dede:listsql}
<!--分頁-->
{dede:pagelist listsize='2' listitem='index pre pageno next end '/}

{dede:sql}和{dede:listsql}的文章鏈接地址<a href="[field:id runphp='yes'] $id=@me ;@me='';$url=GetOneArchive($id);@me=$url['arcurl'];[/field:id]"> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永昌县| 和顺县| 定安县| 巴彦淖尔市| 右玉县| 肥东县| 孟连| 改则县| 珠海市| 门源| 长泰县| 北辰区| 富蕴县| 高雄县| 扬州市| 林西县| 喜德县| 蚌埠市| 江津市| 盘山县| 若羌县| 平湖市| 永城市| 元阳县| 桂阳县| 长宁县| 成安县| 淮北市| 乌拉特后旗| 上林县| 剑阁县| 潮州市| 汶川县| 高青县| 铜川市| 同江市| 仪征市| 昌黎县| 鹿泉市| 定南县| 东阿县|