💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 前端新增代码 * [ ] `介绍` 由于有些功能尚未开发,在原有基础上新加的功能,用法详见模板使用。 ***** ## banner在子页面下公用父级banner图。 ``` <?php // 拿到当前栏目的名 $thisTageName = \think\Config::get("cms.title"); // 拿到父栏目的名 // 判断是否为单页 if(isset($__PAGE__)){ // 获得单页的父级栏目数据,不一定是顶级 $pageData = outlinkFindChannel($__PAGE__['url']); // 判断它是否有父级ID $navId = $pageData['parent_id']?$pageData['parent_id']:$pageData['id']; //判断是否是自定义表单页 }else if(isset($__DIYFORM__)){ $diyFromData = outlinkFindChannel($__DIYFORM__['postUrl']); $navId = $diyFromData['parent_id']?$diyFromData['parent_id']:$diyFromData['id']; // 判断是否是内页, // 兼容一级栏目banner没填,只填了二级栏目时,内页找不到对应父级栏目banner的问题 }else if(isset($__ARCHIVES__)){ $navId = getParentChannel($__ARCHIVES__['channel_id'])['id']; }else{ $navId = $__CHANNEL__['parent_id'] == 0?$__CHANNEL__['id']:$__CHANNEL__['parent_id']; } $fatherName = getParentChannel($navId); // 将bannerKey默认设置为父栏目的名 $bannerKey = $fatherName['name']; ?> <!-- 判断当前栏目是否有banner,如果有就将bannerKey设置为当前栏目的名 --> {cms:blocklist id="block" name="$thisTageName" row="1"} <?php $bannerKey = $thisTageName; ?> {/cms:blocklist} <div class="banner swiper-container"> <div class="banner_wrap swiper-wrapper"> {cms:blocklist id="block" name="$bannerKey" row="5" orderby="weigh" orderway="asc"} <a href="{$block.url}" class="banner_link swiper-slide"> <img src="{$block.image}" alt=""> </a> {/cms:blocklist} </div> <div id="pages_switer"></div> </div> <script> var BannerSwiper = new Swiper('.swiper-container', { pagination: { el: '#pages_switer', clickable: true, }, autoplay: { delay: 5000, disableOnInteraction: false, }, autoHeight: true, }); // 看不见就停止轮播 window.onscroll = function () { var pageHeght = window.scrollY || window.pageYOffset; if (pageHeght > BannerSwiper.wrapperEl.clientHeight) { BannerSwiper.autoplay.stop(); } else if (pageHeght <= BannerSwiper.wrapperEl.clientHeight) { BannerSwiper.autoplay.start(); } } </script> ```