dedecms织梦调用图集的第一张图片的方法

2023-02-20

我们开发织梦内容页模板时,需要调用图集的第一张图片。80站长网把实现方法分享出来。

第一步:打开 \include\extend.func.php 在最下面加入函数
   
 function Getimgurls($aid,$num=1)      {
        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 .= {$row['imgsrc']};
                }
                $i++;
            }
            return $result;
        }
    }


第二步:在内容页用{dede:field.id /}调用以上函数。具体语法如下:

   

完成。

非凡技术导航 优秀网址导航免费网站收录 网站地图

本站收录的网站若侵害到您的利益,请联系我们删除处理

Copyright ©2020 Guojiz V 5.5All Rights Reserved.

备案号 )| 1735737677|