迅睿CMS自适应PC和移动端正文内容中图片不能自适应或太大解决方案

现在很多站长都在使用迅睿搭建自己的个人网站,一些以前使用织梦dedecms程序的个人站长也都纷纷转投其他网站开源程序,今天就给各位分享下迅睿的移动端图片太大该如何解决?

首先找到 /config/custom.php 文件,并在里面添加如下代码

/*
 * 内容图片去宽高自适应
 * @param     string  $body
 * @return    string  返回内容
 */
if(!function_exists('resetBody'))
{
    function resetBody($body)
    {
        $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', $body);
        $content = preg_replace($search1, '$1$3', $content);
        $content = preg_replace($search2, '$1$2', $content);
        $content = preg_replace($search3, '$1$2', $content);
        $result  = str_replace('/uploads/', SITE_URL . '/uploads/', $content);
        return $result;
    }
}

 

然后是模板调用文档内容标签代码

{resetBody($content)}

这样移动端的内容图片就可以按照屏幕的大小来展示了,如果还是有问题你就需要修改一下内容图片的css样式文件了。

 

来源:https://blog.csdn.net/zhang01457/article/details/120945581

posted @ 2025-05-10 16:17  asqq8  阅读(13)  评论(0)    收藏  举报
51LA统计