不用修改程序內(nèi)核文件,不影響電腦站和手機(jī)站文章內(nèi)容頁的文章內(nèi)容輸出,增加個自定義方法來解決織夢MIP文章內(nèi)容頁圖片適配百度MIP規(guī)范
  • 操作步驟
  1. <img 替換成 <mip-img
  2. width|height 去除圖片寬高
  3. style 去除內(nèi)聯(lián)樣式
  4. /uploads/ 相對路徑圖片路徑替換成絕對路徑
打開 /include/extend.func.php 在最下面加入個方法
/**
 *  MIP文章內(nèi)容頁圖片適配百度MIP規(guī)范
 *
 * @access    public
 * @param     string  $content  文章內(nèi)容
 * @return    string
 */
function mip($content){
global $cfg_basehost;
    preg_match_all('/<img (.*?)\>/', $content, $images);
    if(!is_null($images)) {
        foreach($images[1] as $index => $value){
            $mip_img = str_replace('<img', '<mip-img', $images[0][$index]);
            $mip_img = str_replace('>', '></mip-img>', $mip_img);
            $mip_img = preg_replace('/(width|height)="\d*"\s/', '', $mip_img );
            $mip_img = preg_replace('/ style=\".*?\"/', '',$mip_img);
            $content = str_replace($images[0][$index], $mip_img, $content);
        }
    }
    preg_match_all('/ style=\".*?\"/', $content, $style);
    if(!is_null($style)) {
        foreach($style[0] as $index => $value){
            $mip_style = preg_replace('/ style=\".*?\"/', '',$style[0][$index]);
            $content = str_replace($style[0][$index], $mip_style, $content);
        }
    }
$content = str_replace('/uploads/', $cfg_basehost.'/uploads/', $content);
    return $content;  
}
內(nèi)容頁模板標(biāo)簽寫法
{dede:field.body function=mip(@me)/}