DedeCMS自增函數autoindex/itemindex用法全解析:
在使用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]
如果被2整除則輸出豎線否則為空
[field:global name=autoindex runphp="yes"](@me%2==0)? @me="|":@me="";[/field:global]
如果不等于8輸出豎線否則為空,即為8的時候不打印豎線
[field:global name=autoindex runphp="yes"](@me!=8)? @me="|":@me="";[/field:global]
列表每5行有帶劃線
[field:global runphp='yes' name=autoindex]
$a="<li>";
$c="<li class='line'>";
if ((@me % 5) == 0) @me = $c;
else @me = $a;
[/field:global]
在第5行和第10行加廣告,其他行為空
[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]
第一行樣式為class="check",其他行按行數類名字后面id="life_channe1"的數字1實現自增
<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名字后面的數字從0開始自增,判斷如果是第一行則加style="display:none;"屬性,其他行為空
<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} >
對autoindex/itemindex使用自定義函數
先在include/extend.fun.php里添加自定義函數
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="[field:typeurl/]" target=_blank><strong>[field:typename/]</strong></a></div>
</div>
{/dede:channel}
織夢默認的搜索頁不支持autoindex標簽,需要修改核心文件增加支持
找到文件:include/arc.searchview.class.php
里面找到代碼(大概在709行):

$this->dtp2->LoadSource($innertext);
修改為:
$this->dtp2->LoadSource($innertext);
$GLOBALS['autoindex'] = 0;
找到代碼(大概在722行):

if($row = $this->dsql->GetArray("al"))
{
修改為
if($row = $this->dsql->GetArray("al"))
{
$GLOBALS['autoindex']++;
$ids[$row['id']] = $row['id'];
以上就是余斗整理的autoindex/itemindex'用法與擴展,希望能幫到大家。本文轉自網絡,如有侵權,請聯系本站及時刪除。
以上就是DedeCMS自增函數autoindex/itemindex用法全解析的全部內容,希望對大家的學習和解決疑問有所幫助,也希望大家多多支持武林網。新聞熱點
疑難解答