织梦CMS MIP文章内容页图片适配百度MIP规范

相关案例演示

不用修改程序内核文件,不影响电脑站和手机站文章内容页的文章内容输出,增加个自定义方法来解决织梦MIP文章内容页图片适配百度MIP规范

操作步骤

  • <img 替换成 <mip-img
  • width|height 去除图片宽高
  • style 去除内联样式
  • /uploads/ 相对路径图片路径替换成绝对路径

打开 /include/extend.func.php 在最下面加入个方法

/**
 *  MIP文章内容页图片适配百度MIP规范
 *
 * @access    public
 * @param     string  $content  	文章内容
 * @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;  
}

内容页模板标签写法

{dede:field.body function=mip(@me)/}

免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。


来源:网友投稿 关注: 时间:2021-06-16 08:49
首先声明,只要是我们的vip会员所有源码均可以免费下载,不做任何限制(了解更多)
☉本站的源码不会像其它下载站一样植入大量的广告。为了更好的用户体验以后坚持不打水印
☉本站只提供精品织梦源码,源码在于可用,不在多!!希望在这里找到你合适的。
☉本站提供的整站织梦程序,均带数据及演示地址。可以在任一源码详情页查看演示地址
☉本站所有资源(包括源码、模板、素材、特效等)仅供学习与参考,请勿用于商业用途。
☉如有其他问题,请加网站客服QQ进行交流。
相关织梦教程
QQ在线咨询