大家在使用 autoindex 的时候可能会遇到从 1 开始或从 0 开始的情况。下面我们将介绍什么情况下从 0 或 1 开始:
autoindex/itemindex 可以通过 @me+1; 自由定义开始的数字。如果您还不太理解,请继续往下阅读。
### arclist 标签下使用
在 arclist 标签中使用 [field:global.autoindex/] 默认从 1 开始。
{dede:arclist row='10' titlelen='48' typeid='1' channelid='1'}
从1开始:[field:global runphp='yes' name=autoindex][/field:global] 或者 [field:global.autoindex/]
从0开始:[field:global runphp='yes' name=autoindex]@me=@me-1;[/field:global]
{/dede:arclist}
### channel 标签下使用
在 channel 标签中使用 [field:global.autoindex/] 默认从 0 开始。
{dede:channel row='5' type='top'}
从0开始:[field:global runphp='yes' name=autoindex][/field:global] 或者 [field:global.autoindex/]
从1开始:[field:global runphp='yes' name=autoindex]@me=@me+1;[/field:global]
{/dede:channel}
### channelartlist 标签下使用
在 channelartlist 标签中使用 {dede:global.itemindex/} 默认从 1 开始。
{dede:channelartlist row='4'}
从1开始:{dede:global name=itemindex runphp='yes'}{/dede:global} 或者 {dede:global.itemindex/}
从0开始:{dede:global name=itemindex runphp='yes'}@me=@me-1;{/dede:global}
{/dede:channelartlist}
### list 到第10条时输出 `
`
如果需要在循环到第 10 条时输出换行符 `
`,可以按照以下方式实现:
{dede:list pagesize='40' orderby='id'}
[field:title /]
[field:global name='autoindex' runphp='yes']if(@me%10==0){@me="
";}else{@me='';}[/field:global]
{/dede:list}
以上代码中的 `@me%10==0` 表示每 10 条记录后添加一个换行符。您可以根据实际需求调整这个数值。
总结来说,通过合理运用 Dedecms 的 `autoindex` 和 `itemindex`,可以轻松实现多样化的列表样式控制,提升用户体验和页面美观度。