您当前的位置:主页 > 教程合集 > DedeCMS网站首页DedeCMS
DedeCMS自增函数autoindex/itemindex用法全解析
发布时间:2015-12-17编辑:余斗阅读:(0)字号: 大 中 小-
在使用DedeCMS建站的过程中,首页或者列表页的模版会涉及到调用栏目或者子栏目的问题,在调用栏目的时候会在第一个栏目链接中加特别的属性,这里就要用到DedeCMS自带的自增函数[field:global name=autoindex/]和[field:global name=itemindex/],余斗今天就来说说这个[field:global name=autoindex/]和[field:global name=itemindex/]自增函数的一些用法与扩展。
基本用法
autoindex与itemindex都是中都是用@me来表示计数开始,而类似@me+1则可以指定数字开始,在不同的标签中,他们的起始值是不同的:
channelartlist 标签下使用 {dede:global name='itemindex' runphp='yes'}@me;{/dede:global} 是从0开始自增1
channelartlist 标签下使用 {dede:global.itemindex/} 默认从1开始
arclist 标签下使用 [field:global.autoindex/] 默认从1开始
channel 标签下使用 [field:global.autoindex/] 默认从0开始
而如果想要改变起始值则按照以下方式调用:
从0开始[field:global name=autoindex runphp="yes"]@me=@me-1;[/field:global]
从1开始[field:global name=autoindex runphp="yes"]@me=@me+1;[/field:global]
其中,@me=@me±1就能实现对应的起始值,这里自己根据需要修改即可。
扩展用法
起始值加5开始自增计数
[field:global name=autoindex runphp="yes"]@me=@me+5;[/field:global]
[field:global name=autoindex runphp="yes"](@me%2==0)? @me="|":@me="";[/field:global]
[field:global name=autoindex runphp="yes"](@me!=8)? @me="|":@me="";[/field:global]
[field:global runphp='yes' name=autoindex]
$a="<li>";
$c="<li class='line'>";
if ((@me % 5) == 0) @me = $c;
else @me = $a;
[/field:global]
[field:global runphp='yes' name=autoindex]
$a="<div class='box'>";
$b="广告1";
$c="</div>";
$d="广告2";
$e="";
if (@me == 5) @me = $a.$b.$c;
else if (@me == 10) @me = $a.$d.$c;
else @me = $e;
[/field:global]
<li><a href="[field:typeurl/] " [field:global name='autoindex'runphp='yes']if(@me==0){@me='class="check"';}else{@me='id="life_channe'.@me.'" goto="life_channe'.@me.'"';}[/field:global]>[field:typename/]</a></li>
<div id="HomeCon2_1_{dede:global name=itemindex runphp='yes'}@me=@me-1;{/dede:global}" class="HomeCon2_1_1" {dede:global name='itemindex' runphp='yes'}@me=(@me==1)?'':'style="display:none;"';{/dede:global} >
function MyPosition($p){
$positionArr=array(275,330,380,435,495,547);
return $positionArr[$p];
{dede:channel type='son' typeid='13' row='6' noself='yes'}
<!-----侧栏菜单------------------>
<div id='pdv_16795' class='pdv_class' title='' style="width:71px;height:20px;top:[field:global.autoindex function='MyPosition(@me)'/]px;left:136px; z-index:17">
<div style="FONT-FAMILY: SimSun; COLOR: #fecd2e; FONT-SIZE: 15px; fon-weight: bold"><a style="FONT-FAMILY: SimSun; COLOR: #fecd2e; FONT-SIZE: 15px; fon-weight: bold" href="http://lailaikeji.com/spa" style="color:#91268F">"[field:typeurl/]" target=_blank><strong>[field:typename/]</strong></a></div>
</div>
{/dede:channel}

$this->dtp2->LoadSource($innertext);
$this->dtp2->LoadSource($innertext);
$GLOBALS['autoindex'] = 0;

if($row = $this->dsql->GetArray("al"))
{
if($row = $this->dsql->GetArray("al"))
{
$GLOBALS['autoindex']++;
$ids[$row['id']] = $row['id'];