dede 内容页调用自定义模型图片方法

 

修改/include/extend.func.php文件,添加如下代码至末尾:

function GetOneImgUrl($img,$ftype=1){  
    if($img <> ''){  
        $dtp = new DedeTagParse();  
        $dtp->LoadSource($img);  
        if(is_array($dtp->CTags)){  
            foreach($dtp->CTags as $ctag){
                if($ctag->GetName()=='img'){  
                    $width = $ctag->GetAtt('width');  
                    $height = $ctag->GetAtt('height');  
                    $imgurl = trim($ctag->GetInnerText());  
                    $img = '';  
                    if($imgurl != ''){  
                        if($ftype==1){  
                            $img .= $imgurl;  
                        }  
                        else{  
                            $img .= '<img src="'.$imgurl.'" width="'.$width.'" height="'.$height.'" />';  
                        }  
                    }  
                }  
            }  
        }  
        $dtp->Clear();  
        return $img;      
    }  

 

文章页调用代码:{dede:field.alzjimg function='GetOneImgUrl(@me,1)'/} 参数为1,只调用图片地址

        {dede:field.alzjimg function='GetOneImgUrl(@me,0)'/} 参数为0,调用img标签以及宽高

 

 

 

 

 

还有一点提醒一下:

添加自定义字段图片的时候,选择这个

 

 

posted @ 2017-11-28 16:22  azcqwezxc  阅读(1048)  评论(0编辑  收藏  举报