level 2
狂风虎啸天z
楼主
今天做项目的时候遇到在内容页调用自定义图片、百度上面大多都是列表页显示的、
其实很简单、却耽误了我好长时间。
自定义字段直接:{dede:field.cpbh/} cpbh自定义字段名
图片: 字段设置成 图片(仅网址)的格式 {dede:field.图片字段/}
找到:/include/extend.func.php ,在< ?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.*" />*;
}
}
}
}
}
$dtp->Clear();
return $img;
}
}
2014年10月23日 01点10分
1
其实很简单、却耽误了我好长时间。
自定义字段直接:{dede:field.cpbh/} cpbh自定义字段名
图片: 字段设置成 图片(仅网址)的格式 {dede:field.图片字段/}
找到:/include/extend.func.php ,在< ?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.*" />*;
}
}
}
}
}
$dtp->Clear();
return $img;
}
}