运营狗 - 第一张图片 2019-05-27T15:07:00+08:00 Typecho https://blog.seo135.com/feed/atom/tag/%E7%AC%AC%E4%B8%80%E5%BC%A0%E5%9B%BE%E7%89%87/ <![CDATA[织梦DedeCMS获取图集第一张图片方法]]> https://blog.seo135.com/514.html 2019-05-27T15:07:00+08:00 2019-05-27T15:07:00+08:00 运营狗 https://www.seogo.me 打开/include/extend.func.php

把下面代码放在 extend.func.php 最后

// 获取图集图片[新增的功能]
function Getimgs($aid, $imgwith = 240, $imgheight = 285, $num = 0){ 
    global $cfg_basedir;
    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++){ 
    $imglist .= "" . trim($wordcount[2][$i]) . ""; 
} 
if($num>0){return $imglist;}
else{
    $row = $dsql -> getone("Select litpic From`dede_archives` where id='$aid'");
    if($row['litpic']=='')
    {
        $row['litpic'] = '/images/defaultpic.gif';
    }
    return  $row['litpic'];
} 
}

在内容页输出

//240为宽度,285为高度,1为图片数量
{dede:field.aid function='Getimgs(@me,240,285,1)'/} 
]]>