当前位置 : 主页 > 网站建设 > 正文

DedeCMS内容页列表页调用自定义图片地址

原创

重庆seo2015-09-15 08:33:00阅读()dedecms自定义字段A+ / A-

DedeCMS内容页列表页调用自定义图片地址

dede调用自定义图片

       DedeCMS有很多标签调用时自带了HTML代码,其实留给自己处理更好更灵活。比如自定义字段为图片时(字段名:name),输出的格式有时候并不是我们想要的,内容页用{dede:field.name/}

{dede:img text='' width='270' height='129'}/uploads/101017/1-10101H21F54P.gif{/dede:img} 

前台输出格式如下:

<li>
 <a href='/uploads/140420/1-140420164Z2914.jpg' target='_blank'>
 <img src='/uploads/140420/1-140420164Z2914.jpg' width='253' border='0'/>
 </a>
</li>

创建自定义函数

       打开/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;      
    }  
}  

      前台内容页格式为:

<img alt="{dede:field.title/}" src="{dede:field.name function='GetOneImgUrl(@me,1)'/}">
@me,0  代表只输出路径
@me,1  代表连宽、高一起输出

      同样的列表页或首页用相应的标签套进去就行了。

    扩展阅读

    本文地址:https://www.vi586.com/web/211.html
    版权声明:原创文章,版权归重庆SEO吖七所有,欢迎分享本文,支持原创,转载请保留出处

    赞(5)