后臺(tái)的多圖帶描述默認(rèn)的程序是只有標(biāo)題和描述兩個(gè)字段:
假如我們需要三個(gè)字段,要如何處理呢?
好的,現(xiàn)在開始對(duì)代碼進(jìn)行修改:
第一步:先修改后臺(tái)的HTML代碼,content.html如果你的專題頁也需要的話,就也修改一下:single.html
如果我們是對(duì)多圖帶描述進(jìn)行修改,就搜索24,對(duì)附件修改,可以找26。在1320行左右,在foreach循環(huán)中,我們需要添加一行代碼:
<dt><input type='text' name='".$name."|subtitle[]' value='".$value2['subtitle']."' placeholder='副標(biāo)題' class='subtitle-input' style='width:95%'/></dt>
這個(gè)地方是修改文章時(shí)顯示之前提交的數(shù)據(jù),將subtitle顯示出來,注意一下,這里的CLASS里面使用的類名,因?yàn)楹竺嬖贘S生成的時(shí)候都要用到。
第二步:我們先修改一下數(shù)據(jù)保存:
打開:ContentController.php,同樣搜索24找到多圖文處理之處
添加一行副標(biāo)題的代碼,如下:一共有兩處,都添加新增的一行代碼即可。
case 24: // 多圖文處理 case 26: // 多附件處理 if($field_data) { $pics_arr = explode(',', $field_data); $pics_arr2 = []; foreach ($pics_arr as $key2 => $value2) { $pics_arr2[$key2]['src'] = $pics_arr[$key2]; $pics_arr2[$key2]['title'] = array_values(post($value->name . '|title'))[$key2]; $pics_arr2[$key2]['subtitle'] = array_values(post($value->name . '|subtitle'))[$key2]; //這是新增加的一行 $pics_arr2[$key2]['desc'] = array_values(post($value->name . '|desc'))[$key2]; } $field_data = serialize($pics_arr2); } else { $field_data = ''; } break;
這個(gè)時(shí)候,我們已經(jīng)可以通過修改的方式看到副標(biāo)題能顯示了。但是在新增加文章和通過圖庫生成的時(shí)候,還不能顯示。
第三步:
為何在添加文章的時(shí)候,不需要修改呢,因?yàn)樘砑游恼碌臅r(shí)候是通過JS動(dòng)態(tài)生成的,我們看HTML代碼就可以看到,他是通過:
<a class="layui-btn layui-btn-warm" onclick="GetPictureFolder(100,'[value->name]','3');"><i class="layui-icon layui-icon-picture"></i>圖庫</a> 通過圖庫動(dòng)態(tài)生成 <script type="text/javascript">picsSortable('[value->name]'); </script> 通過上傳圖片動(dòng)態(tài)生成
所以我們首先修改通過上傳圖片動(dòng)態(tài)生成的位置:
在mylayui.js中。 //執(zhí)行多圖片上傳實(shí)例中,type=3里面,我們新增一行副標(biāo)題:
"<dt><input type='text' name='" + des + "|subtitle[]' value='' placeholder='副標(biāo)題' class='subtitle-input' style='width:95%'/></dt>" + // ← 新增副標(biāo)題
變成:
html3 += "<dl><dt><img src='" + sitedir + value + "' data-url='" + value + "' alt='" + picsname[index] + "'></dt><a class='replace replace_" + des + desk + "'>更換</a><dd>刪除</dd>" + "<dt><input type='text' name='" + des + "|title[]' value='" + picsname[index] + "' placeholder='標(biāo)題' class='title-input' style='width:95%'/></dt>" + "<dt><input type='text' name='" + des + "|subtitle[]' value='' placeholder='副標(biāo)題' class='subtitle-input' style='width:95%'/></dt>" + // ← 新增副標(biāo)題 "<dt><textarea name='" + des + "|desc[]' placeholder='描述' class='layui-textarea' style='display:unset;height:50px;min-height:50px;width:95%'></textarea></dt>" + "</dl>";
然后在comm.js中找到:
function picsSortable(field, upinput = true) { $(document).ready(function() { var group = (field == 'pics') ? 'pic' : 'pics'; var sortable = new Sortable(document.getElementById(field + '_box'), { group: group, ghostClass: 'sortable-bg', fallbackTolerance: 3, animation: 150, onEnd: function(evt) { var data = $('#' + field + '_box dl dt img').map(function() { return $(this).data("url"); }).get(); if (upinput) { $('input[name=' + field + ']').val(data.join(",")); } var newName = $(evt.item).parent('.pic').attr('id').replace('_box', ''); var $input = $(evt.item).find('input.title-input'); $input.attr('name', $input.attr('name').replace(field, newName)); if (field != 'pics') { var $textarea = $(evt.item).find('textarea.layui-textarea'); $textarea.attr('name', $textarea.attr('name').replace(field, newName)); } var newData = $('#' + newName + '_box dl dt img').map(function() { return $(this).data("url"); }).get(); if (upinput) { $('input[name=' + newName + ']').val(newData.join(",")); } if (field !== newName) { layer.msg('跨組拖拽排序完成!', { icon: 6 }); } } }); }); }
并修改成如下代碼:
function picsSortable(field, upinput = true) { $(document).ready(function () { var group = (field == 'pics') ? 'pic' : 'pics'; var sortable = new Sortable(document.getElementById(field + '_box'), { group: group, ghostClass: 'sortable-bg', fallbackTolerance: 3, animation: 150, onEnd: function (evt) { // 重新整理圖片URL順序,寫回隱藏input var data = $('#' + field + '_box dl dt img').map(function () { return $(this).data("url"); }).get(); if (upinput) { $('input[name=' + field + ']').val(data.join(",")); } // 拖拽的dl對(duì)應(yīng)的新字段名 var newName = $(evt.item).parent('.pic').attr('id').replace('_box', ''); // 標(biāo)題 var $titleInput = $(evt.item).find('input.title-input'); $titleInput.attr('name', $titleInput.attr('name').replace(field, newName)); // 副標(biāo)題 var $subtitleInput = $(evt.item).find('input.subtitle-input'); $subtitleInput.attr('name', $subtitleInput.attr('name').replace(field, newName)); // 描述 var $textarea = $(evt.item).find('textarea.layui-textarea'); $textarea.attr('name', $textarea.attr('name').replace(field, newName)); // 更新對(duì)應(yīng)input值(圖片路徑集合) var newData = $('#' + newName + '_box dl dt img').map(function () { return $(this).data("url"); }).get(); if (upinput) { $('input[name=' + newName + ']').val(newData.join(",")); } // 提示跨組 if (field !== newName) { layer.msg('跨組拖拽排序完成!', { icon: 6 }); } } }); }); }
由此,通過上傳圖片也可以自動(dòng)生成:圖片,標(biāo)題,副標(biāo)題,描述了。
但是通過圖庫直接選擇圖片還不行。
第四步: 修改通過圖庫自動(dòng)生成。
在后臺(tái)找到:media_index.html,修改代碼:
else if (inputType == '3') { html += "<dl><dt><img src='" + sitedir + images_array[i] + "' data-url='" + images_array[i] + "' alt='" + images_name_array[i] + "'></dt><dd>刪除</dd>" + "<dt><input type='text' name='" + inputId + "|title[]' value='" + images_name_array[i] + "' placeholder='標(biāo)題' class='title-input' style='width:95%'/></dt>" + "<dt><input type='text' name='" + inputId + "|subtitle[]' placeholder='副標(biāo)題' class='subtitle-input' style='width:95%'/></dt>" + //新增副標(biāo)題 "<dt><textarea name='" + inputId + "|desc[]' placeholder='描述' class='layui-textarea' style='display:unset;height:50px;min-height:50px;width:95%'></textarea></dt>" + "</dl>"; }
按以上步驟,基本上就完成了此次改造。
多附件添加副標(biāo)題字段
既然多圖都加了副標(biāo)題了。那么多附件最好也加一個(gè)副標(biāo)題吧。因?yàn)楹芏嗟胤接昧讼嗤拇a。
多附件擴(kuò)展是26,所以
第一步:我們在content.html中搜索:26
在1400行左右,修改內(nèi)容的地方添加:
<dt><input type='text' name='".$name."|subtitle[]' value='".$value2['subtitle']."' placeholder='附件副標(biāo)題' class='subtitle-input' style='width:95%'/></dt>
第二步:修改content的控制器,在上面的修改多圖中,我們已經(jīng)修改過了,他們用的是相同的代碼,所以這里就不需要修改了。
第三步:在mylaui.js中找到: //執(zhí)行多附件上傳實(shí)例
添加代碼:
"<dt><input type='text' name='" + des + "|subtitle[]' placeholder='附件副標(biāo)題' class='subtitle-input' style='width:95%'/></dt>" +
因?yàn)楦郊际且蟼魑募?,所以就不用像上面考慮圖庫直接拉取圖片或者文件的問題了。
由此,改造完成。
我們的網(wǎng)站后臺(tái)默認(rèn)有一個(gè)留言的提醒數(shù)據(jù):但是如果要有多個(gè)留言表單,那么我們自定義的留言表單卻沒有這個(gè)...
在之前的文章中,我們有講過,如何使用擴(kuò)展字段來此入HTML代碼并添加預(yù)覽功能。文章鏈接可查看:https://ww...
以下內(nèi)容來源于PB交流QQ群。第一:NGINX配置。#攔截常見敏感后臺(tái)路徑訪問(例如dede、admin、wp-login等),...
在外貿(mào)網(wǎng)站建設(shè)中,我們會(huì)遇到有客戶說需要用戶前端留言的時(shí)候可以上傳自定義的文件或者圖片等資料。那么這...