大部分手机站都是自适应的,这样图片就不能有宽高限制,我们添加文章图片时很多时候都会有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: \d+px;([^"]*?.*?>)#i';
$search3 = '#(<img.*?style=".*?)height: \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/allimg/', $cfg_basehost.'/uploads/allimg/', $content);//手机版图片使用绝对路径
{/dede:field.body}
DedeCMS织梦工场QQ群
群号(23871657)
只适用于讨论dedecms二次开发相关话题,其他闲聊、广告、斗图、捣乱请自重自觉,谢谢合作!
不忘初心 、方得始终
DedeCMS织梦工场 - 致力于把最实用的DedeCms二次开发教程,DedeCms二次开发视频,DedeCms二次开发实例经验,分享给最需要的站长,希望每一位来访的站长都能有所收获!
如果您认为本网站的内容质量不错或者读后成功解决你心中的难题,觉得收获很大,那么不妨小额赞助一下,让我们有动力继续写出高质量的教程与更棒的程序教程。打赏记录
赞助方式
支付宝手机客户端扫描上面的二维码进行赞助
微信手机客户端扫描上面的二维码进行赞助