dede织梦调用缩略图原图的方法

2019年4月2日22:01:29 发表评论 1,931 views

第一种

方法是网上很早流传的代码类似如下:

打开 /include/common.func.php在最后面加入如下代码:

function firstpic($str_pic) 
{ 
    $str_sub=substr($str_pic,0,-7).".jpg";//删除缩略图字符串最后七位,然后再补上后缀.jpg 
    return $str_sub; 
}

标签中调用:

[field:litpic function=firstpic('@me')/]

直接调用:

{dede:field name='litpic' function="firstpic(@me)"/}

上面的方法可以是可以,但是我们用图片不一定全是jpg,可能是png、gif又或是其他格式,那么这种情况这个.jpg就不太合适了。这时候可以试试第二种。

第二种

说它是自动识别,其实只是用了字符串切割的方法,如果勾选提取第一个图片萎缩路人图的话,文章的缩略图和第一张图片只多了一个“-lp”的字符串,

用php的“str_replace”函数切割一下就行了。方法如下:

打开 /include/common.func.php在最后面加入如下代码:

function firstpic($str_pic) 
{ 
    $str_sub=str_replace("-lp","","$str_pic");  //删除缩略图中的"-lp"。
    return $str_sub; 
}

标签中调用:

[field:litpic function=firstpic('@me')/]

直接调用:

{dede:field name='litpic' function="firstpic(@me)"/}

第三种

通过比较明显第二种方法比较好。但是如果自己上传缩略图的话,貌似第二种就用不了了,这时候就要再用另一种方法:

打开 /include/helpers/archive.helper.php 在最后面加入如下代码

if(!function_exists('GetImgs'))
{
    function GetImgs($aid)
    {
        global $dsql;
        $query = "select body FROM `dede_addonarticle` where aid='$aid'";
        $dsql->Execute('body',$query);
        $row = $dsql->GetArray('body');
        preg_match('//i',$row['plot'],$str);
        $GImgs = $str[2];
        return $GImgs;
    }
}

调用:

[field:id function=GetImgs(@me)/]

 

 

 

 

 

 

 

 

 

 

历史上的今天:


欢迎来到菜鸟头头的个人博客
本文章百度已收录,若发现本站有任何侵犯您利益的内容,请及时邮件或留言联系,我会第一时间删除所有相关内容。

  • A+
所属分类:WEB

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: