国产沈阳熟女视频|骚视频97网站一区日本在线视频|久1社区在线视频|综合久久国外自产拍无码精品视频|亚洲欧美Tv先锋|综合五月天网址制服丝袜在线露脸|1024欧美手机视频我不卡|日本二区欧美亚洲国产|丁香五月婷婷五月|综合 另类 一区

    <li id="0tgns"></li>
    <center id="0tgns"></center>

        284292114@qq.com 中國站
        行業(yè)新聞 網(wǎng)站建設(shè) 網(wǎng)絡(luò)推廣 首頁>新聞中心>網(wǎng)站建設(shè)

        多圖帶標(biāo)題添加多一個字段副標(biāo)題使用。

        時間:2025-10-12   訪問量:0

        后臺的多圖帶描述默認(rèn)的程序是只有標(biāo)題和描述兩個字段:

        多圖帶標(biāo)題添加多一個字段副標(biāo)題使用。

        假如我們需要三個字段,要如何處理呢?

        多圖帶標(biāo)題添加多一個字段副標(biāo)題使用。


        好的,現(xiàn)在開始對代碼進(jìn)行修改:


        第一步:先修改后臺的HTML代碼,content.html如果你的專題頁也需要的話,就也修改一下:single.html

        如果我們是對多圖帶描述進(jìn)行修改,就搜索24,對附件修改,可以找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>

        這個地方是修改文章時顯示之前提交的數(shù)據(jù),將subtitle顯示出來,注意一下,這里的CLASS里面使用的類名,因為后面在JS生成的時候都要用到。


        第二步:我們先修改一下數(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;

        這個時候,我們已經(jīng)可以通過修改的方式看到副標(biāo)題能顯示了。但是在新增加文章和通過圖庫生成的時候,還不能顯示。


        第三步:

        為何在添加文章的時候,不需要修改呢,因為添加文章的時候是通過JS動態(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>  通過圖庫動態(tài)生成
         <script type="text/javascript">picsSortable('[value->name]'); </script>  通過上傳圖片動態(tài)生成

        所以我們首先修改通過上傳圖片動態(tài)生成的位置:

        在mylayui.js中。 //執(zhí)行多圖片上傳實例中,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對應(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));
        
                        // 更新對應(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 });
                        }
                    }
                });
            });
        }


        由此,通過上傳圖片也可以自動生成:圖片,標(biāo)題,副標(biāo)題,描述了。

        但是通過圖庫直接選擇圖片還不行。


        第四步: 修改通過圖庫自動生成。

        在后臺找到: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)題了。那么多附件最好也加一個副標(biāo)題吧。因為很多地方用了相同的代碼。

        多附件擴(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í)行多附件上傳實例

        添加代碼:

        "<dt><input type='text' name='" + des + "|subtitle[]'   placeholder='附件副標(biāo)題' class='subtitle-input' style='width:95%'/></dt>" +

        因為附件都是要上傳文件,所以就不用像上面考慮圖庫直接拉取圖片或者文件的問題了。

        由此,改造完成。以上可以將數(shù)據(jù)保存到數(shù)據(jù)庫中了。

        但是前端在顯示的時候,無法使用:

        pics:subtitle


        所以我們需要再修改一下:ParserController.php 中的兩個地方。找到: public function parserContentPicsLabel  這個位置函數(shù)。新增副標(biāo)題部分的代碼的代碼。

        // 讀取內(nèi)容多圖
                        if (!!$rs) {
                            // 獲取模型字段類型 @LiuXiaoBai
                            $type = $this->model->getExtfieldType($field);
                            // 特殊多圖字段判斷 @LiuXiaoBai
                            if ($targetType == 'label' || ($targetType == 'sort' && $type != '10') || $type == '24' || $type == '26') {
                                $pics = [];
                                $picstitle = [];
                                $picssubtitle = [];  //新增副標(biāo)題
                                $picsdesc = [];
                                $picsarr = unserialize($rs);
                                foreach ($picsarr as $key => $value) {
                                    $pics[] = $value['src'];
                                    $picstitle[] = $value['title'];
                                    $picssubtitle[] = $value['subtitle'];  //新增副標(biāo)題
                                    $picsdesc[] = $value['desc'];
                                }
                            } else {
                                $pics = explode(',', $rs);
                                $picstitle = explode(',', $rs->picstitle);
                            }
                        } else {
                            $pics = [];
                            $picstitle = [];
                        }


        同時在下面添加:

         case 'title':
                                        $one_html = str_replace($matches2[0][$j], $this->adjustLabelData($params, isset($picstitle[$vkey]) ? $picstitle[$vkey] : ''), $one_html);
                                        break;
                                    case 'subtitle':  //新增副標(biāo)題
                                    $one_html = str_replace($matches2[0][$j],$this->adjustLabelData($params, isset($picssubtitle[$vkey]) ? $picssubtitle[$vkey] : ''),$one_html);
                                        break;



        服務(wù)咨詢
        1對1咨詢,專業(yè)客服為您解疑答惑
        聯(lián)系銷售
        15899750475
        在線咨詢
        聯(lián)系在線客服,為您解答所有的疑問