首页 > CMS > 织梦DEDE > 正文

织梦手机模板如何去除文章内容中图片的宽和高来自适应以及使用绝对路径图片

2024-07-12 08:49:06
字体:
来源:转载
供稿:网友
这篇文章主要为大家详细介绍了织梦手机模板如何去除文章内容中图片的宽和高来自适应以及使用绝对路径图片,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,有需要的朋友可以收藏方便以后借鉴。

      手机网站最重要的一点就是能自适应,这是因为手机屏幕大小太多,需要根据不同的屏幕大小显示不同的页面尺寸来适应不同的手机屏幕大小。因此想要实现自适应那么图片就不能有宽高限制,而我们在使用织梦系统我们添加文章图片时很多时候都会有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}

效果在请测试后在给我们一些反馈吧。

以上就是织梦手机模板如何去除文章内容中图片的宽和高来自适应以及使用绝对路径图片的全部内容,希望对大家的学习和解决疑问有所帮助,也希望大家多多支持武林网。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表