码迷,mamicode.com
首页 > 其他好文 > 详细

织梦图集图片在首页列表页调用并且自定义输出几张

时间:2018-11-04 19:28:08      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:src   技术分享   rom   clear   i++   images   from   new   ges   

不改动官方核心文件,在自定义方法文件里加入个方法来实现织梦图集图片在首页列表页调用并且自定义输出几张

效果展示

技术分享图片

教程实现

打开 include\extend.func.php 在最下面加入这个方法

function Getimgurls($aid,$num=4)    
{
    global $dsql;
    $imgurls = $result = ‘‘;
    $imgrow = $dsql->GetOne( "Select imgurls From `#@_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;
    }  
}

上面html代码部分改成你自己的,注意单双引号

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

首页/列表页标签调用写法

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

数字4是调用几张图片

织梦图集图片在首页列表页调用并且自定义输出几张

标签:src   技术分享   rom   clear   i++   images   from   new   ges   

原文地址:https://www.cnblogs.com/dedevip/p/9904675.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!