在这个文件的最底部添加以下方法:
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 .= " ";
}
$i++;
}
return $result;
}
}
以下是默认的HTML输出格式: 请确保将其更改为适合您页面设计的HTML代码。 接下来,在前台模板中调用该函数时,可以使用以下代码:
[field:id function=Getimgurls(@me,3)/]