余弘烨重庆 發表於 2023-12-4 00:00:00

dedecms获取图片集多张图片实现方法(循环输出)

<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>在为客户做网站的时候需要做到的效果是每个案例都要很多<u>图片</u>,并且用一定的效果进行展示。但是发现织梦本身自带的调取方法实现的效果是一次性调取多个参数,并且展现的效果不是我需要的,当时很纠结。后来自己琢磨琢磨,可惜没成功。最后通过网络百度搜索找到了实现方法。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>实现的方法一共有两个步骤: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>1、在/include/common.func.php 里加上方法 //循环输出多张图片function </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode13" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        function Getimgs($aid, $imgwith = 300, $imgheight = 270, $num = 0, $style = ''){ <br>
        global $dsql; <br>
        $imgurls = ''; <br>
        $row = $dsql -&gt; getone("Select imgurls From`dede_addonimages` where aid='$aid'"); // <br>
        $imgurls = $row['imgurls']; <br>
        preg_match_all("/{dede:img (.*)}(.*){\/dede:img/isU", $imgurls, $wordcount); <br>
        $count = count($wordcount); <br>
        if ($num &gt; $count || $num == 0){ <br>
        $num = $count; <br>
        } <br>
        for($i = 0;$i &lt; $num;$i++){ <br>
        if($style == 'li'){ <br>
        $imglist .= "&lt;li&gt;&lt;ahref=#" . $i . "&gt;&lt;imgsrc=". trim($wordcount[$i]) . " width=" . $imgwith . " height=" . $imgheight . "&gt;&lt;/li&gt;&lt;/a&gt;"; <br>
        }else{ <br>
        $imglist .= "&lt;img src= " . trim($wordcount[$i]) . " width=" . $imgwith . "height=" . $imgheight . "&gt;"; <br>
        } <br>
        } <br>
        return $imglist; <br>
        } </div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>2、在模板里调用方法{dede:field.id function="Getimgs(@me,400,400,10)" /}</span>
頁: [1]
查看完整版本: dedecms获取图片集多张图片实现方法(循环输出)