有一些朋友的網站前端不需要縮略圖,只需要個別文章顯示縮略圖,PbootCMS模板默認自動提取文章裏的圖片作爲縮略圖。其實可以增加一個按鈕,判斷下就可以。最終實現效果如下:

找到文件
apps\admin\view\default\content\content.html(在代碼340行及740行,添加以下代碼)
1 | <div class= "layui-form-item" > |
2 | <label class= "layui-form-label" >內容圖片設置</label> |
3 | <div class= "layui-input-block" > |
4 | <input type = "checkbox" name= "contenttopic" value= "1" title= "內容首圖設置縮略圖" > |
5 | <input type = "checkbox" name= "contenttopics" value= "1" title= "內容圖片設置多圖" > |
|
找到文件apps\admin\controller\content\ContentController.php
在代碼96/428行
1 | $contenttopic = post( 'contenttopic' );//設置內容首圖按鈕 |
2 | $contenttopics = post( 'contenttopics' );//設置內容圖片爲多圖按鈕 |
|
在代碼136/468行處添加02 | if ($contenttopic && preg_match( '/<img\s+.*?src=\s?[\'|\"](.*?(\.gif|\.jpg|\.png|\.jpeg))[\'|\"].*?[\/]?>/i' , decode_string($content), $srcs) && isset($srcs[1])) { |
06 | // 设置内容图片为多图,不适用内容图片很多的情况 adminbuy.cn |
07 | if ($contenttopics && preg_match_all( '/<img\s+.*?src=\s?[\'|\"](.*?(\.gif|\.jpg|\.png|\.jpeg))[\'|\"].*?[\/]?>/i' , decode_string($content), $srcs)) { |
08 | $strsrcs = implode( "," , $srcs[1]); |
|
以上是文章添加的代碼,文章修改的代碼也是一樣