百度MIP是百度推出的手機版加速應用,主要是為了提升手機端頁面訪問速度,同時官方還明確MIP網站還可以優先收錄和提升流量,非常適合流量站用戶使用。但隨著國內網速的體式,MIP的意義就隨之不是那么重要了,網上很多朋友也都說MIP涼涼了,但是精準像素看到百度官網還有MIP更新信息,也沒看到百度明確說不在對MIP網站提供優勢輔助了。那么精準像素覺得還是可以試著能做就做一個MIP網站,畢竟不是很難。
在制作MIP模板之前,我們首先要了解MIP的制作要求有哪些。
以下只列出常用的語法規范,具體的大家可以去官網查看:https://www.mipengine.org/doc/2-tech/1-mip-html.html
<img>需替換為 <mip-img>
<iframe>需替換為 <mip-iframe>
<form> 需替換為 <mip-form>
<script>type 必須 text/javascript 、application/javascript
<a>需替換為 <mip-link>
同時圖片標簽上禁止出現其他屬性標簽,比如:style、width、height等等。還有百度統計、百度分享、百度廣告等都有對應的百度MIP語法。
所以針對這些要求我們就需要對模板進行這些標簽的替換就行。
1、后臺新建一個MIP終端
2、img、iframe、form、script、a等常用標簽改造,只需要在MIP終端內替換模板字段,把<img 替換字符 <mip-img就可以了。
這些標簽改造大家自行試試就知道怎么弄了。
3、內容頁的newstext改造,newstext是寫數據庫的,所以用模板替換功能,肯定是不行的,這里就需要用其他的方法了。
1 | <?= str_replace ( array ( '<img' , '<IMG' ), '<mip-img' ,preg_replace( "/s.*?>/si" , ">" , $navinfor [ 'newstext' ]));?> |
把內容模板內的newstext標簽替換成上面的代碼就可以了,替換內容newstext字段內的img和去除img上的style屬性。
至此,簡單的帝國CMS百度mip改造就完成了,本教程適合模板結構不是很復雜的模板mip改造。如果模板相對復雜的以后有時間精準像素會為大家分享利用帝國CMS函數的方法來替換改造。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 百度統計 < mip-stats-bidu token = "百度統計后臺獲取" ></ mip-stats-bidu > < script src = "https://mipcache.bdstatic.com/static/mipmain-v0.0.1.js" ></ script > < a href = "http://www.11px.cn/tags/bdfx/" target = "_blank" >百度分享</ a > < script src = "https://mipcache.bdstatic.com/static/v0.1/mip-share.js" ></ script > < script src = "https://mipcache.bdstatic.com/static/v1.1/mip-stats-bidu.js" ></ script > 百度廣告 < script src = "https://mipcache.bdstatic.com/static/v0.2/mip-ad.js" ></ script > < a href = "http://www.11px.cn/tags/cy/" target = "_blank" >暢言</ a > < mip-changyan ? appid = "cytbHGFzU" ? conf = "prod_79d1813385059b7a4473cddaeb0ccf0e" ? critical-width = "960" > < div ? id = "SOHUCS" ></ div > </ mip-changyan > < script src = " https://mipcache.bdstatic.com/static/v1/mip-changyan/mip-changyan.js" ></ script > 返回上一頁 < mip-history history = "go, -1" class = "mip-history-default" layout = "responsive" width = "3" height = "1" >←返回</ mip-history > 統計 < mip-pix src = "[!--news.url--]e/public/onclick/?t=${TIME}&title=${TITLE}&id=${HOST}" ></ mip-pix > |
新聞熱點
疑難解答