织梦园模板网提供云优cms模板,pbootcms模板,Wordpress主题模板等各类企业新闻资讯网站模板下载服务。织梦园网站模板交流群
用户名:
密码:
注册
注册后享受折扣价

织梦dede模板图集在首页或列表页调用并自定义显示几张图

织梦园模板 / 2019-06-20 / 收藏
打开 include/extend.func.php 在***下面加入这个方法
function Getimgurls($aid,$num=4)   
{
    global $dsql;
    $imgurls = $result = '';
    $imgrow = $dsql->GetOne( "Select imgurls From `dede_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表示,此篇图集调用三张图片。

相关织梦教程

收缩