找到conf/FunctionsExt.php。添加如下函数
function lazyImg($richText) {
    return preg_replace_callback(
        '/<img\s+([^>]*)\s*>/i',
        function ($matches) {
            $attributes = $matches[1];
            $newAttributes = str_replace('src=', 'data-src=', $attributes);
            return str_replace($attributes, $newAttributes, $matches[0]);
        },
        $richText
    );
}
找到/app/home/c/HomeController.php
找到 function jizhi_details($id){}函数里面
把$con = $details['body'];
改成$con = lazyImg($details['body']);
前端引入懒加载插件,即可完成

标签: 极致cms

您需要先登录才能发表评论。