织梦DedeCMS手机端内容图片如何自适应手机屏幕

2021年2月26日09:44:38 发表评论
微信搜一搜 ts小陈

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

方法如下:

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

  1. {dede:field.body runphp=yes}
  2. global $cfg_basehost;
  3. $str = @me;
  4. $search = '/(<img.*?)width=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is';
  5. $search1 = '/(<img.*?)height=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is';
  6. $search2 = '#(<img.*?style=".*?)width:\d+px;([^"]*?.*?>)#i';
  7. $search3 = '#(<img.*?style=".*?)height:\d+px;([^"]*?.*?>)#i';
  8. $content = preg_replace($search,'$1$3',$str);
  9. $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}
小陈号卡
ts小陈

发表评论(不允许含有网址!)

:?: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :cry: :mrgreen: :neutral: :razz:

已登录用户不需要填写以下内容