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

前端之家收集整理的这篇文章主要介绍了DedeCMS图集首页列表页调用并自定义输出几张前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。编程之家小编现在分享给大家,也给大家做个参考。

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

function Getimgurls($aid,$num=4)

{

global $dsql;

$imgurls = $result = '';

$imgrow = $dsql->GetOne( "Select imgurls From `mydiy_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 .= "<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>";

}

$i++;

}

return $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>

上面这段代码改成符合自己页面的 html 格式,前台模板中调用代码如下:

[field:id function=Getimgurls(@me,3)/]

其中 3 表示,此篇图集调用三张图片

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

猜你在找的Dedecms相关文章