美文网首页
DedeCMS自增函数autoindex/itemindex用法

DedeCMS自增函数autoindex/itemindex用法

作者: 阿修哥 | 来源:发表于2017-12-29 16:58 被阅读15次

    在使用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="

  1. ";
  2. $c="

  3. ";
  4. 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实现自增

  5. [field:typename/]
  6. 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'];

    相关文章

      网友评论

          本文标题:DedeCMS自增函数autoindex/itemindex用法

          本文链接:https://www.haomeiwen.com/subject/xsfwgxtx.html