[field:global name=’autoindex’ runphp=’yes’]@me=@me+1;[/field:global]
织梦dedecms模板制作时,我们需要每循环一次,变量加一,这是就需要使用到autoindex标签。代码写法如下:
{dede:arclist titlelen=’26’ row=’10’}
<li><a title=”[field:title function=’htmlspecialchars(@me)’/] ” href=”[field:arcurl /]”>[field:title /]</a></li>
[field:global name=autoindex runphp=”yes”]if(@me%5==0)@me=”<br/>”;else @me=””;[/field:global]
{/dede:arclist}
红色的即为autoindex标签用法。意思是,循环调用文章时,到第五条时输出<br/>,否则输出空。这样我们就实现了第五篇文章下面进行换行。配合css和简单的php等代码使用,达到更多效果。
循环+1的写法:
[field:global name=autoindex runphp=”yes”]@me=@me+1;[/field:global]
频道页使用时可以换成itemindex标签,原理同autoindex
{dede:global name=’itemindex’/}
{dede:global name=’itemindex’ runphp=’yes’}if(@me%5==0)@me=”<br/>”;else @me=””;{/dede:global}
{dede:global name=’itemindex’ runphp=’yes’}@me=@me+1;{/dede:global}
织梦默认的搜索页不支持autoindex标签,需要修改核心文件增加支持:
找到文件:include/arc.searchview.class.php
里面找到代码:$this->dtp2->LoadSource($innertext);
下面加上:
$GLOBALS[‘autoindex’] = 0;
————————————
if($row = $this->dsql->GetArray(“al”))
{
下面加上:
$GLOBALS[‘autoindex’]++;
$ids[$row[‘id’]] = $row[‘id’];
2011-10-22 11:11 autoindex对于织梦模板的基本和高级应用方法 1.基本用法:
[field:global name=autoindex /] 或者
[field:global.autoindex /]
举例:
{dede:arclist row=’5′ row=10}
[field:global name=autoindex /]<a href='[field:arcurl/]’ >[field:title/]</a>
{/dede:arclist}
上面的这个例子就可以显示带数字序号。
稍微高级点的用法
{dede:arclist row=’5′ row=10}
< li><a href='[field:arcurl/]’ >[field:title/]</a></li>
{/dede:arclist}
这样你只要定义不同的css,a1,a2,a3,a4,就可以每行不同的css效果
2.高级用法(使用自定义函数或者runphp=”yes”):
[field:global.autoindex runphp=’yes ‘] …php基本语句… [/field:global .autoindex ] 或者
[field:global.autoindex function=myfunc(@me) /] myfunc是个自定义函数,关于自定义函数的写法请参考本站其他文章
在这里主要讲runphp=’yes’ 组合的用法,下面用个例子来实现4列的表格的实现
举例
[field:global.autoindex runphp=’yes ‘] …php基本语句… [/field:global .autoindex ]
<table> <tr>
{dede:arclist row=’5′ row=10}
< td><a href='[field:arcurl/]’ >[field:title/]</a></td>
[field:global.autoindex runphp=’yes ‘] if (@me % 4==0){@me=”</tr><tr>”;} else{@me=””;} [/field:global .autoindex ]
{/dede:arclist}
</tr></table>
解释下:也就是说autoindex对4整除余数为0(取摸)的时候就插入</tr><tr>,这样就表格换行了。
自定义函数的写法类似,不过用自定义函数可以实现更复杂的php语句。对于这样的写法需要一定的php基础