|
当使用 channelartlist标签 嵌套artlist 标签时,想要各个子栏目的样式不一样,或者指定调用某几个子栏目,比如调用当前栏目的第四个第八个栏目,使用row肯定不行,这时我们想到artlist支持limit调用,但是channelartlist不支持。
临时想个法子 在channelartlist加个limit标签
修改 \include\taglib\channelartlist.lib.php 文件标签代码如下
- <?php if(!defined('DEDEINC')) exit('Request Error!');
- /**
- * 获取当前频道的下级栏目的内容列表标签
- *
- * @version $Id: channelartlist.lib.php 1 9:29 2010年7月6日Z tianya $
- * @package DedeCMS.Taglib
- * @copyright Copyright (c) 2007 - 2010, DesDev, Inc.
- * @license http://help.dedecms.com/usersguide/license.html
- * @link http://www.dedecms.com
- */
- /*>>dede>>
- <name>频道文档</name>
- <type>全局标记</type>
- <for>V55,V56,V57</for>
- <description>获取当前频道的下级栏目的内容列表标签</description>
- <demo>
- {dede:channelartlist row=6}
- <dl>
- <dt><a href='{dede:field name='typeurl'/}'>{dede:field name='typename'/}</a></dt>
- <dd>
- {dede:arclist titlelen='42' row='10'} <ul class='autod'>
- <li><a href="[field:arcurl /]">[field:title /]</a></li>
- <li>([field:pubdate function="MyDate('m-d',@me)"/])</li>
- </ul>
- {/dede:arclist}
- </dl>
- {/dede:channelartlist}
- </demo>
- <attributes>
- <iterm>typeid:频道ID</iterm>
- <iterm>row:获取的栏目返回值</iterm>
- </attributes>
- >>dede>>*/
- require_once(DEDEINC.'/arc.partview.class.php');
- function lib_channelartlist(&$ctag,&$refObj)
- {
- global $dsql,$envs,$_sys_globals;
- //处理标记属性、innertext
- $attlist = 'typeid|0,row|20,cacheid|,limit|,type|'; //这边加个limit变量 type 我是想实现 在子栏目下调用 同级子栏目的信息
- FillAttsDefault($ctag->CAttribute->Items,$attlist);
- extract($ctag->CAttribute->Items, EXTR_SKIP);
- $innertext = trim($ctag->GetInnerText());
- $artlist = '';
- //读取固定的缓存块
- $cacheid = trim($cacheid);
- if($cacheid !='') {
- $artlist = GetCacheBlock($cacheid);
- if($artlist!='') return $artlist;
- }
- if(empty($typeid))
- {
- $typeid = ( !empty($refObj->TypeLink->TypeInfos['id']) ? $refObj->TypeLink->TypeInfos['id'] : 0 );
- }
- if($innertext=='') $innertext = GetSysTemplets('part_channelartlist.htm');
- $totalnum = $row;
- if(empty($totalnum)) $totalnum = 20;
- //获得类别ID总数的信息
- $typeids = array();
- if($type=='reid') //2011.7.5 调用上级目录下的子栏目内容
- {
- $reid = $refObj->TypeLink->TypeInfos['reid'];
- $tpsql = " reid='$reid' AND ispart<>2 AND ishidden<>1 ";
- }
- else if($typeid==0 || $typeid=='top') {
- $tpsql = " reid=0 AND ispart<>2 AND ishidden<>1 AND channeltype>0 ";
- }
- else
- {
- if(!preg_match('#,#', $typeid)) {
- $tpsql = " reid='$typeid' AND ispart<>2 AND ishidden<>1 ";
- }
- else {
- $tpsql = " id IN($typeid) AND ispart<>2 AND ishidden<>1 ";
- }
- }
- $limit = trim(preg_replace('#limit#is', '', $limit)); //增加limit标签
- if($limit!='') $limitsql = " LIMIT $limit "; //如果limit为空就以 row变量的默认值 限制
- else $limitsql = " LIMIT 0,$totalnum";
- $dsql->SetQuery("SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
- FROM `dede_arctype` WHERE $tpsql ORDER BY sortrank ASC $limitsql");
- $dsql->Execute();
- while($row = $dsql->GetArray()) {
- $typeids[] = $row;
- }
- if(!isset($typeids[0])) return '';
- $GLOBALS['itemindex'] = 0;
- $GLOBALS['itemparity'] = 1;
- for($i=0;isset($typeids[$i]);$i++)
- {
- $GLOBALS['itemindex']++;
- $pv = new PartView($typeids[$i]['id']);
- $pv->Fields['typeurl'] = GetOneTypeUrlA($typeids[$i]);
- $pv->SetTemplet($innertext,'string');
- $artlist .= $pv->GetResult();
- $GLOBALS['itemparity'] = ($GLOBALS['itemparity']==1 ? 2 : 1);
- }
- //注销环境变量,以防止后续调用中被使用
- $GLOBALS['envs']['typeid'] = $_sys_globals['typeid'];
- $GLOBALS['envs']['reid'] = '';
- if($cacheid !='') {
- WriteCacheBlock($cacheid, $artlist);
- }
- return $artlist;
- }
复制代码
这样就可以实现了
在同一栏目分别调用
{dede:channelartlist limit='0,1'} 大栏目下 第一个子栏目
{dede:arclist row='6'}
{/dede:arclsit}
{/dede:channelartlist}
{dede:channelartlist limit='1,1'}大栏目下 第二个子栏目
{dede:arclist row='6'}
{/dede:arclsit}
{/dede:channelartlist}
上面就可以在一个模板中调用
如果在子栏目下 调用同级栏目的信息
{dede:channelartlist type='reid' limit='0,1'}
{dede:arclist row='6'}
{/dede:arclist}
{/dede:channelartlist}
|
|