在開發織夢模板時,如果有你使用到dede:productimagelist標簽,就會發現,該標簽沒有autoindex自動索引,使用
[field:global.autoindex/]
無法調用。這時候我們就需要做個二次開發,讓dede:productimagelist標簽支持autoindex。
1:打開/include/taglib/productimagelist.lib.php 找到:
foreach($images as $row)
在其上面增加如下代碼
$GLOBALS['autoindex'] = 1;//如果您希望autoindex 的起始值從0開始,把1修改成0即可。
繼續找到如下代碼:
$revalue .= $ctp->GetResult();
在其下面增加:
$GLOBALS['autoindex']++;
完成。
2:標簽調用:
{dede:productimagelist} <span id="[field:global name=autoindex/]"><img src="[field:imgsrc/]" /></span> {/dede:productimagelist}產生的結果:
<span id="0"><img src="1.jpg" /></span> <span id="1"><img src="2.jpg" /></span> <span id="2"><img src="3.jpg" /></span>
或者使用:
{dede:productimagelist} <div class="item [field:global runphp='yes' name=autoindex](@me < 2)?@me="active":@me="";[/field:global]"> <img src="[field:imgsrc/]"/> </div> {/dede:productimagelist}產生的結果:
<div class="item active"> <img src="/1.jpg"/> </div><div class="item "> <img src="/2.jpg"/> </div><div class="item "> <img src="/3.jpg"/> </div>
完成。
新聞熱點
疑難解答