Browse Source

📦 按要求修改轮播图

快乐的梦鱼 3 weeks ago
parent
commit
4fa14cb4b7
6 changed files with 42 additions and 30 deletions
  1. 19 0
      CommonQuery.php
  2. 1 1
      danWeiGaiKuang.php
  3. 19 26
      index.php
  4. 1 1
      lianXiWoMeng.php
  5. 1 1
      luDaoWenMai.php
  6. 1 1
      zhengCeFaGui.php

+ 19 - 0
CommonQuery.php

@@ -196,4 +196,23 @@ function getContentById($id) {
             print_r($e);
         return null;
     }
+}
+
+/**
+ * 从pr_cms_block表中获取banner数据
+ * @return array 轮播图数据数组
+ */
+function getBannerData() {
+    try {
+        // 从pr_cms_block表中查询name=banner的数据
+        $bannerData = Db::table('pr_cms_block')
+            ->where('name', 'banner')
+            ->where('status', 'normal')
+            ->get();
+        
+        return $bannerData ?? [];
+    } catch (Exception $e) {
+        // 发生异常时返回空数组
+        return [];
+    }
 }

+ 1 - 1
danWeiGaiKuang.php

@@ -42,7 +42,7 @@ if (!$currentArticle) {
 // 轮播图数据
 $carouselItems = [
   [
-    "image" => "/images/test-header-3.png",
+    "image" => "/uploads/20251013/6af88ead615998ad6c789327b26f7bbe.jpg",
     "alt" => $channelName
   ]
 ];

+ 19 - 26
index.php

@@ -1,21 +1,8 @@
 <?php
 require 'CommonQuery.php';
 
-// 轮播图数据
-$carouselItems = [
-  [
-    "image" => "/images/test-header-1.png",
-    "alt" => "厦门市文化遗产宣传图"
-  ],
-  [
-    "image" => "https://picsum.photos/id/1036/1200/400",
-    "alt" => "厦门风景图"
-  ],
-  [
-    "image" => "https://picsum.photos/id/1037/1200/400",
-    "alt" => "厦门文化遗产保护"
-  ]
-];
+// 轮播图数据 - 从pr_cms_block表中获取
+$carouselItems = getBannerData();
 $carouselItems2 = loadListByChannelName(6, "热门新闻");
 // 通知公告数据
 $notices = loadListByChannelName(10, "新闻公告");
@@ -49,18 +36,24 @@ $featured = loadListByChannelName(6, "热门新闻");
   <?php include __DIR__ . '/components/navbar.php'; ?>
 
   <!-- 轮播图 -->
-  <div class="swiper mySwiper" style="width: 100%; height: 400px;">
-    <div class="swiper-wrapper">
-      <?php foreach ($carouselItems as $item): ?>
-        <div class="swiper-slide">
-          <img src="<?php echo $item['image']; ?>" alt="<?php echo $item['alt']; ?>" style="width: 100%; height: 100%; object-fit: cover;">
-        </div>
-      <?php endforeach; ?>
+    <div class="swiper mySwiper" style="width: 100%; height: 400px;">
+      <div class="swiper-wrapper">
+        <?php foreach ($carouselItems as $item): ?>
+          <div class="swiper-slide">
+            <?php if (!empty($item['url'])): ?>
+              <a href="<?php echo $item['url']; ?>" target="_blank">
+                <img src="<?php echo $item['image']; ?>" alt="<?php echo $item['title'] ?? '轮播图'; ?>" style="width: 100%; height: 100%; object-fit: cover;">
+              </a>
+            <?php else: ?>
+              <img src="<?php echo $item['image']; ?>" alt="<?php echo $item['title'] ?? '轮播图'; ?>" style="width: 100%; height: 100%; object-fit: cover;">
+            <?php endif; ?>
+          </div>
+        <?php endforeach; ?>
+      </div>
+      <div class="swiper-pagination"></div>
+      <div class="swiper-button-prev"></div>
+      <div class="swiper-button-next"></div>
     </div>
-    <div class="swiper-pagination"></div>
-    <div class="swiper-button-prev"></div>
-    <div class="swiper-button-next"></div>
-  </div>
 
   <!-- 主要内容 -->
   <div class="main-content">

+ 1 - 1
lianXiWoMeng.php

@@ -2,7 +2,7 @@
 // 轮播图数据 - 联系我们页面
 $carouselItems = [
   [
-    "image" => "/images/test-header-8.png",
+    "image" => "/uploads/20251013/47d9f2bcd627ab15d4e5014b50166440.jpg",
     "alt" => "联系我们"
   ]
 ];

+ 1 - 1
luDaoWenMai.php

@@ -4,7 +4,7 @@ require_once 'CommonQuery.php';
 // 轮播图数据 - 修改为单张图片
 $carouselItems = [
   [
-    "image" => "/images/test-header-6.png",
+    "image" => "/uploads/20251013/246147ec48aeefa28998917497f2ef6b.jpg",
     "alt" => "鹭岛文脉"
   ]
 ];

+ 1 - 1
zhengCeFaGui.php

@@ -4,7 +4,7 @@ require_once 'CommonQuery.php';
 // 轮播图数据 - 修改为单张图片
 $carouselItems = [
   [
-    "image" => "/images/test-header-7.png",
+    "image" => "/uploads/20251013/6af88ead615998ad6c789327b26f7bbe.jpg",
     "alt" => "政策法规"
   ]
 ];