dedecms图集在首页或列表页调用并自定义输出几张
作者:king 日期:2023-05-20 分类:CMS教程
打开 \include\extend.func.php 在最下面加入这个方法
01 |
function Getimgurls($aid,$num=4) |
04 |
$imgurls = $result = ''; |
05 |
$imgrow = $dsql->GetOne( "Select imgurls From `mydiy_addonimages` where aid='$aid' "); |
06 |
$imgurls = $imgrow['imgurls']; |
09 |
$dtp = new DedeTagParse(); |
10 |
$dtp->LoadSource($imgurls); |
12 |
if(is_array($dtp->CTags)) |
14 |
foreach($dtp->CTags as $ctag) |
16 |
if($ctag->GetName() == 'img') |
19 |
$row['width'] = $ctag->GetAtt('width'); |
20 |
$row['height'] = $ctag->GetAtt('height'); |
21 |
$row['imgsrc'] = trim($ctag->GetInnerText()); |
22 |
$row['text'] = $ctag->GetAtt('text'); |
29 |
foreach($images as $row) |
32 |
if($row['imgsrc'] != '') |
34 |
$result .= "<li><div class='pic'><a title='{$row['text']}' href='{$row['imgsrc']}'><img src='{$row['imgsrc']}' mid='{$row['imgsrc']}' big='{$row['imgsrc']}' width='70' height='70'></a></div></li>"; |
|
请注意
1 |
<li><div class='pic'><a title='{$row['text']}' href='{$row['imgsrc']}'><img src='{$row['imgsrc']}' mid='{$row['imgsrc']}' big='{$row['imgsrc']}' width='70' height='70'></a></div></li> |
|
上面这段代码改成符合自己页面的html格式。前台模板中调用代码如下:
1 |
[field:id function=Getimgurls(@me,3)/] |
|
3表示,此篇图集调用三张图片。