DedeCMS织梦

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

阿里云

DedeCMS 图集在首页列表页调用并且自定义输出几张图片,不改动官方核心文件。打开 \include\extend.func.php 在最下面加入这个方法:

  1. function Getimgurls($aid,$num=4)    
  2. {
  3.     global $dsql;
  4.     $imgurls = $result = '';
  5.     $imgrow = $dsql->GetOne( "Select imgurls From `mydiy_addonimages` where aid='$aid' ");
  6.     $imgurls = $imgrow['imgurls'];
  7.     if($imgurls != '')
  8.     {
  9.         $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 表示,此篇图集调用三张图片。

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

已有 293 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!