织梦DedeCMS手机端文章内容图片设置自适应屏幕

网站建设 2022-07-27 09:12www.1681989.com免费网站
织梦dedecms 默认的文章内容里面的图片是固定大小的,这样在手机端里面就可能会导致图片不能完整显示,甚至把屏幕撑开,这样非常不友好,所以这里就给大家分享一个方法,让手机 […]



默认的文章内容里面的图片是固定大小的,这样在手机端里面就可能会导致图片不能完整显示,甚至把屏幕撑开,这样非常不友好,所以这里就给大家分享一个方法,让手机端的文章内容里面的图片能够自适应图片大小。

 

方法如下

 

找到并打开手机端的文章内容页模板,将里面的{dede:field.body/}标签修改一下,改为如下的标签

 

查看源码
 
打印代码帮助
01 {dede:field.body runphp=yes}
02 global $cfg_basehost;
03 $str = @me;
04 $search '/(<img.?)width=(["\'])?.?(?(2)\2|\s)([^>]+>)/is';
05 $search1 '/(<img.?)height=(["\'])?.?(?(2)\2|\s)([^>]+>)/is';
06 $search2 '#(<img.?style=".?)width:\d+px;([^"]?.?>)#i';
07 $search3 '#(<img.?style=".?)height:\d+px;([^"]?.?>)#i';
08 $content = preg_replace($search,'$1$3',$str);
09 $content = preg_replace($search1,'$1$3',$content);
10 $content = preg_replace($search2,'$1$2',$content);
11 $content = preg_replace($search3,'$1$2',$content);
12 @me = $content;
13 //@me = str_replace('/uploads/allimg/', $cfg_basehost.'/uploads/allimg/', $content);//手机版图片使用绝对路径
14 {/dede:field.body}


也就是通过php代码将文章内容里面的图片标签的宽度高度全部去掉,这样就可以了。

Copyright © 2016-2025 www.1681989.com 推火网 版权所有 Power by