导航
当前位置:网站首页 > 站长新闻 > CMS教程 > dedecms图集在首页或列表页调用并自定义输出几张

dedecms图集在首页或列表页调用并自定义输出几张

作者:king 日期:2023-05-20 分类:CMS教程

打开 \include\extend.func.php 在最下面加入这个方法

01 function Getimgurls($aid,$num=4)   
02 {
03     global $dsql;
04     $imgurls = $result = '';
05     $imgrow = $dsql->GetOne( "Select imgurls From `mydiy_addonimages` where aid='$aid' ");
06     $imgurls = $imgrow['imgurls'];
07     if($imgurls != '')
08     {
09         $dtp = new DedeTagParse();
10         $dtp->LoadSource($imgurls);
11         $images = array();
12         if(is_array($dtp->CTags))
13         {
14             foreach($dtp->CTags as $ctag)
15             {
16                 if($ctag->GetName() == 'img')
17                 {
18                     $row = array();
19                     $row['width'] = $ctag->GetAtt('width');
20                     $row['height'] = $ctag->GetAtt('height');
21                     $row['imgsrc'] = trim($ctag->GetInnerText());
22                     $row['text'] = $ctag->GetAtt('text');
23                     $images[] = $row;
24                 }
25             }
26         }
27         $dtp->Clear();
28         $i = 0;
29         foreach($images as $row)
30         {
31             if($i == $num) break;
32             if($row['imgsrc'] != '')
33             {
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>";
35             }
36             $i++;
37         }
38         return $result;
39     
40 }
请注意
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表示,此篇图集调用三张图片。

猜你还喜欢