Home > CMS Tutorial > DEDECMS > body text

How to call dede:img on the Dreamweaver list page

藏色散人
Release: 2019-11-15 10:27:46
Original
1948 people have browsed it

How to call dede:img on the Dreamweaver list page

织梦列表页如何调用dede:img?

织梦列表页调用dede:img

首先是网上的方法

1)创建自定义函数

打开 /include/extend.func.php 文件(注:这个文件就是系统预留的自定义函数接口文件,主要用于二次开发用的。如果你是老版本,默认没有这个文件,自己创建一个PHP文件即可),在最下面的?>上一行加入以下函数代码:

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

[field:自定义图片字段名 function="GetOneImgUrl(@me,显示类型)"/]

比如:我们的自定义图片字段名为 imgurl ,那么调用方式有以下两种:

引用

[field:imgurl function=&#39;GetOneImgUrl(@me,0)&#39;/] <!--调用图片的信息,自动调用宽度和高度(已包含Html代码的<img />标签)-->
[field:imgurl function=&#39;GetOneImgUrl(@me,1)&#39;/] <!--只调用图片地址,一般可用于背景图嵌套-->
Copy after login

通过以上方法在dede:arclist标签中可以调用图片了,但记得在dede:arclist标签的后面添加上自定义字段的名字和模型ID,即:

{dede:arclist row=&#39;2&#39; channeld=&#39;1&#39; addfields=&#39;自定义字段1,自定义字段2&#39;}
 [field:imgurl function=&#39;GetOneImgUrl(@me,0)&#39;/] 
{/dede:arclist}
Copy after login

这样才能调用出来

但是如果在列表页中,在dede:list标签中,样式就会发生变化了,这时候需要修改

/templets/system/channel_article_image.htm文件,将其改成你想用的样式即可。

The above is the detailed content of How to call dede:img on the Dreamweaver list page. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!