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="

  • ";
  • $c="

  • ";
  • if?((@me %5) ==0) @me = $c;

    else?@me = $a;

    [/field:global]

    在第5行和第10行加廣告,其他行為空

    [field:global?runphp='yes'name=autoindex]

    $a="

    ";

    $b="廣告1";

    $c="";

    $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實現自增

  • [field:typename/]
  • Div中id名字后面的數字從0開始自增,判斷如果是第一行則加style="display:none;"屬性,其他行為空

    對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'}


    [field:typename/]

    {/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'];

    ?著作權歸作者所有,轉載或內容合作請聯系作者
    平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

    推薦閱讀更多精彩內容