有時候我們需要控制在channelartlist下的每一個子欄目的樣式,例如:
我現在有三個欄目,A所使用的class和其它欄目不一樣:
欄目A的代碼爲<div class="on">欄目A</div>
欄目B的代碼爲<div class="off">欄目B</div>
欄目C的代碼爲<div class="off">欄目C</div>
那麼,我們可以使用
{dede:global.itemindex runphp='yes'}
if((@me-1)==0){
@me = 'on';
}
else{
@me = 'off';
}
{/dede:global.itemindex}
完整代碼爲:
{dede:channelartlist}
<div class="
{dede:global.itemindex runphp='yes'}
if((@me-1)==0){
@me = 'on';
}
else{
@me = 'off';
}
{/dede:global.itemindex}
">{dede:field name='typename'/}</div>
{/dede:channelartlist}
如果想要換其它的控制樣式的方法,只需要修改if中的公式,以下還有幾種可以作爲參考:
第一個欄目與其它欄目不同樣式的寫法,if((@me-1)==0)
隔行換樣式的寫法,if((@me %2) == 0)
在arclist標籤下的使用方法:
[field:autoindex runphp='yes']
if((@me=$GLOBALS['autoindex'])==0){
@me = 'on';
}
else{
@me = 'off';
}
[/field:autoindex]