学习笔记

精准传达 • 价值共享

洞悉互联网前沿资讯,探寻网站营销规律

查看其它板块

织梦让手机站的图片变成自适应 并且绝对路径

作者:狐灵科技 | 2020-02-22 15:53 |点击:

大部分手机站都是自适应的,这样图片就不能有宽高限制,我们添加文章图片时很多时候都会有width height style这些属性在里面,在手机站上要把它们清除并且让图片和附件都使用上绝对路径,又不能影响电脑站的,不修改程序内核文件,我们可以在手机版内容页模板里,

把手机站内容页模板把调用文章内容的标签,找到

{dede:field.body/}

改成

{dede:field.body runphp=yes}
global $cfg_basehost;
$str = @me;
$search = '/(<img.*?)width=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is';
$search1 = '/(<img.*?)height=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is';
$search2 = '#(<img.*?style=".*?)width:\s{0,}\d+px;([^"]*?.*?>)#i';
$search3 = '#(<img.*?style=".*?)height:\s{0,}\d+px;([^"]*?.*?>)#i';
$content = preg_replace($search,'$1$3',$str);
$content = preg_replace($search1,'$1$3',$content);
$content = preg_replace($search2,'$1$2',$content);
$content = preg_replace($search3,'$1$2',$content);
@me = str_replace('/uploads/', $cfg_basehost.'/uploads/', $content);
{/dede:field.body}

如果是栏目内容的图片要自适应的话那标签

{dede:field.content/}

改成

{dede:field.content runphp=yes}
global $cfg_basehost;
$str = @me;
$search = '/(<img.*?)width=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is';
$search1 = '/(<img.*?)height=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is';
$search2 = '#(<img.*?style=".*?)width:\s{0,}\d+px;([^"]*?.*?>)#i';
$search3 = '#(<img.*?style=".*?)height:\s{0,}\d+px;([^"]*?.*?>)#i';
$content = preg_replace($search,'$1$3',$str);
$content = preg_replace($search1,'$1$3',$content);
$content = preg_replace($search2,'$1$2',$content);
$content = preg_replace($search3,'$1$2',$content);
@me = str_replace('/uploads/', $cfg_basehost.'/uploads/', $content);
{/dede:field.content}

 

 

 


如没特殊注明,文章均为狐灵科技原创,转载请注明  https://www.hulingweb.cn/qxpp/xuexibiji/946.html
多一份免费策划方案,总有益处。

请直接添加技术总监微信联系咨询

网站设计 品牌营销

多一份参考,总有益处

联系狐灵科技,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:023-68168040 / 大客户专线:15523356218