首页  »  站长资讯  »  网站优化

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

2023/03/11 12:26     创新屋收录网     已浏览352次


打开 includeextend.func.php 在最下面加入这个方法





















01

function Getimgurls($aid,$num=4)   











02

{











03

    global $dsql;











04

    $imgurls = $result = '';











05

    $imgrow = $dsql->GetOne( "Select imgurls From `mydiy_addonimages` where aid='$aid' ");











06

    $imgurls = $imgrow['imgurls'];











07

    if($imgurls != '')











08

    {











09

        $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 .= "
  • "
    ;











    35

                }











    36

                $i++;











    37

            }











    38

            return $result;











    39

        











    40

    }






    请注意












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




















    1

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






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