在织梦DEDECMS列表页调用指定栏目ID 并且有分页功能,该怎么实现

在织梦DEDECMS列表页调用指定栏目ID 并且有分页功能,该怎么实现,第1张

织梦。在dedecms中具有分页浏览的新闻列表页新闻栏目内容调用标是织梦,如果某个字段需要在前台列表页显示,则在前台参数中勾选“使字段可以在列表的底层模板中获得(自定义字段默认仅能在文档模板显示。

我们可以另外嵌入一个类似{dede:listsql sql='select from wp_posts' pagesize='10'}的标签来使用。

OK,思路已经有了,接下来我们打开include/arclistviewclassphp这个文件来给它动个小手术吧!

找到:

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; } } } //end

然后找到:

if($ctag->GetName()=="list") { $limitstart = ($this->PageNo-1) $this->PageSize; $row = $this->PageSize; if(trim($ctag->GetInnerText())=="") { $InnerText = GetSysTemplets("list_fulllisthtm"); } 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_fulllisthtm"); } else { $InnerText = trim($ctag->GetInnerText()); } $this->dtp->Assign($tagid, $this->GetSqlList( $limitstart, $row, $ctag->GetAtt("sql"), $InnerText ) ); } //end

最后找到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_fulllisthtm'); } //处理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

总共就添加三段代码,每一段代码基本都参考它紧接着的上面那段原始代码,而无需改变它原来任何一个地方的代码,应该算是比较完美的手术了,接下来在模板文件中的使用方法就跟一开始思路中所提到的那样,分页标签依旧沿用原来的,调用范例:

{dede:listsql sql='select ID,post_title from wp_posts' pagesize='10'} <li><a href="http://ys21426blog163com/[field:ID /]html">[field:post_title /]</a></li> {/dede:listsql} <!--分页--> {dede:pagelist listsize='2' listitem='index pre pageno next end '/}

解决在一个空栏目中,调用已有信息栏目的内容:

在栏目管理中,修改 空栏目的属性,如图:

在栏目交叉中选择手工指定交叉栏目ID,就可以了。

乱码问题 , 你现在查看一下你的浏览器是否是utf8 , 还有就是你的html页面是不是utf-8 ,还有一点就是你这个html文件是否是utf-8文件。 不知道你用的是什么编辑器。 但是没有编辑器都可以修改这个文件的编码。 还有就是你下载的dedecms是gbk还是utf-8 。 4点只要保持一致就不会乱码。只要一个错都会导致乱码问题。

DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
网站模板库 » 在织梦DEDECMS列表页调用指定栏目ID 并且有分页功能,该怎么实现

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情