我們開發織夢內容頁模板時,需要調用圖集的第一張圖片。所以武林網織夢模板把實現方法分享出來。
第一步:打開 /include/extend.func.php 在最下面加入函數
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | function Getimgurls($aid,$num=1) { global $dsql; $imgurls = $result = ''; $imgrow = $dsql->GetOne( "Select imgurls From `dede_addonimages` where aid='$aid' "); $imgurls = $imgrow['imgurls']; if($imgurls != '') { $dtp = new DedeTagParse(); $dtp->LoadSource($imgurls); $images = array(); if(is_array($dtp->CTags)) { foreach($dtp->CTags as $ctag) { if($ctag->GetName() == 'img') { $row = array(); $row['width'] = $ctag->GetAtt('width'); $row['height'] = $ctag->GetAtt('height'); $row['imgsrc'] = trim($ctag->GetInnerText()); $row['text'] = $ctag->GetAtt('text'); $images[] = $row; } } } $dtp->Clear(); $i = 0; foreach($images as $row) { if($i == $num) break; if($row['imgsrc'] != '') { $result .= {$row['imgsrc']}; } $i++; } return $result; } } |
第二步:在內容頁用{dede:field.id /}調用以上函數。具體語法如下:
<img src="{dede:field.id function=Getimgurls(@me)/}" />
完成。



















