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

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

操作步骤

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

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

01/**
02 *  MIP文章内容页图片适配百度MIP规范
03 *
04 * @access    public
05 * @param     string  $content      文章内容
06 * @return    string
07 */
08function mip($content){
09    global $cfg_basehost;
10    preg_match_all('/<img (.*?)\>/', $content, $images);
11    if(!is_null($images)) {
12        foreach($images[1] as $index => $value){
13            $mip_img = str_replace('<img''<mip-img', $images[0][$index]);
14            $mip_img = str_replace('>''></mip-img>', $mip_img);
15            $mip_img = preg_replace('/(width|height)="\d*"\s/''', $mip_img );
16            $mip_img = preg_replace('/ style=\".*?\"/''',$mip_img);
17            $content = str_replace($images[0][$index], $mip_img, $content);
18        }
19    }
20    preg_match_all('/ style=\".*?\"/', $content, $style);
21    if(!is_null($style)) {
22        foreach($style[0] as $index => $value){
23            $mip_style = preg_replace('/ style=\".*?\"/''',$style[0][$index]);
24            $content = str_replace($style[0][$index], $mip_style, $content);
25        }
26    }
27    $content = str_replace('/uploads/', $cfg_basehost.'/uploads/', $content);
28    return $content; 
29}

内容页模板标签写法

查看源码打印代码帮助
1{dede:field.body function=mip(@me)/}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值