栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > php开源框架 > dedecms

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

dedecms 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

织梦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,400,10)" /}

     

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

    注释:"是调取出来的格式,可根据自己需要的样式进行定义,比如加个li或者 添加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", $imgurls, $wordcount);
         $count = count($wordcount[1]);
         if ($num > $count || $num == 0){
            $num = $count;
        }
        for($i = 0;$i < $num;$i++){
            if($style == 'li'){
                $imglist .= "

  • ";
            }else{
                $imglist .= "". trim($wordcount[1][$i]) .""; 
            }
        }
         return $imglist;
         } 

    2,

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

     

    转载请注明:文章转载自 www.mshxw.com
    本文地址:https://www.mshxw.com/it/8715.html
    我们一直用心在做
    关于我们 文章归档 网站地图 联系我们

    版权所有 (c)2021-2022 MSHXW.COM

    ICP备案号:晋ICP备2021003244-6号