POST TIME:2017-10-26 20:06
織夢dedecms默認的文章內容里面的圖片是固定大小的,這樣在手機端里面就可能會導致圖片不能完整顯示,甚至把屏幕撐開,這樣非常不友好,所以這里就給大家分享一個方法,讓手機端的文章內容里面的圖片能夠自適應圖片大小。
方法如下:
找到并打開手機端的文章內容頁模板,將里面的{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 = $content; //@me = str_replace('/uploads/allimg/', $cfg_basehost.'/uploads/allimg/', $content);//手機版圖片使用絕對路徑 {/dede:field.body} |