织梦dedecms获取图片集多张图片及注释的方法(循环输出)

在为客户做网站的时候需要做到的效果是每个案例都要很多图片,并且用一定的效果进行展示。但是发现织梦本身自带的调取方法实现的效果是一次性调取多个参数,并且展现的效果不是我需要的,当时很纠结。后来自己琢磨琢磨,可惜没成功。最后通过网络百度搜索找到了实现方法

 

实现效果如图:

织梦dedecms获取图片集多张图片及注释的方法(循环输出)

 

 

实现的方法一共有两个步骤:

1、在/include/common.func.PHP 里加上方法 //循环输出多张图片function
function Getimgs($aid, $imgwith = 300, $imgheight = 270, $num = 0, $style = ''){
    global $dsql;
    $imgurls = '';
     $row = $dsql -> getone("Select imgurls From`dede_addonimages` where aid='$aid'"); //
     $imgurls = $row['imgurls'];
     preg_match_all("/{dede:img (.*)}(.*){\/dede:img/isU", $imgurls, $wordcount);
     $count = count($wordcount[2]);
     if ($num > $count || $num == 0){
        $num = $count;
    }
    
    for($i = 0;$i < $num;$i++){
        if($style == 'li'){
            $imglist .= "

  • ";
            }else{
                $imglist .= "         }
        }
         return $imglist;
         }

     

     

    2、在模板里调用方法{dede:field.id function="Getimgs(@me,400,10)" /}

     

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    注释:添加class等等,这里就不多讲了。

    原文出自

    http://blog.sina.com.cn/s/blog_458e0a9401015d4d.html

     

     

    希望这篇文章对大家有帮助,如果有错误,5k欢迎大家多多定评指出噢。交流才会进步!

     

     

     

    以下方法是调取图片集多张图片注释的方法,操作类似。

    1,在/include/common.func.PHP 里加上

    //循环输出多张图片注释
    function Getimgnote($aid, $num = 0){
        global $dsql;
        $imgurls = '';
         $row = $dsql -> getone("Select imgurls ` where aid='$aid'"); //
         $imgurls = $row['imgurls'];
         preg_match_all("|text='(.*)' width|U", $wordcount);
         $count = count($wordcount[1]);
         if ($num > $count || $num == 0){
            $num = $count;
        }
        for($i = 0;$i < $num;$i++){
            if($style == 'li'){
                $imglist .= "

  • ";
            }else{
                $imglist .= ""; 
            }
        }
         return $imglist;
         } 

    2,

    2、在模板里调用方法{dede:field.id function="Getimgnote(@me,10)" /}

  • 相关文章

    本教程操作系统:Windows10系统、DedeCMS 5.7.109版本、Dell...
    在Dedecms织梦列表页中是肯定要使用pagelist标签的,但是有的...
    今天分享织梦网站怎么搬家,个人感觉织梦的搬家比其他的程序...
    织梦(dede)程序不安全是公认的,同样是建站,使用织梦程序...
    使用xemu、爱站工具包、尖叫青蛙等制作网站地图,每次生成si...
    分享织梦自动生成网站sitemap,但是需要安装插件,今天分享,...