CommonCategory.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. // 引入公共查询类
  3. require_once 'CommonQuery.php';
  4. // 主频道名称
  5. $mainChannelName = $inMainChannelName;
  6. // 使用loadChildChannelByChannelName函数获取子分类
  7. $sideMenu = loadChildChannelByChannelName($mainChannelName);
  8. // 获取URL参数
  9. $selectedChannel = isset($_GET['channel']) ? $_GET['channel'] : '';
  10. $currentPage = isset($_GET['page']) ? intval($_GET['page']) : 1;
  11. // 验证当前页码
  12. if ($currentPage < 1) {
  13. $currentPage = 1;
  14. }
  15. // 每页显示的文章数量
  16. $pageSize = 12;
  17. // 确定要查询的频道名称
  18. $queryChannel = !empty($selectedChannel) ? $selectedChannel : $mainChannelName;
  19. // 如果没有结果但选择了子分类,尝试查询主频道下所有子频道的文章
  20. if (empty($selectedChannel)) {
  21. // 从sideMenu中提取所有id
  22. $channelIds = [];
  23. if (!empty($sideMenu)) {
  24. $channelIds = array_map(function($item) {
  25. return $item['id'] ?? null;
  26. }, $sideMenu);
  27. // 过滤掉空值
  28. $channelIds = array_filter($channelIds);
  29. }
  30. $results = loadListByChannelIdInNameAndPage($pageSize, $channelIds, $currentPage);
  31. $queryChannel = $mainChannelName;
  32. } else {
  33. $results = loadListByChannelNameAndPage($pageSize, $queryChannel, $currentPage);
  34. }
  35. $workUpdates = $results['list'];
  36. $totalPages = $results['totalPages'];
  37. // 轮播图数据
  38. $carouselItems = getBannerData();
  39. ?>
  40. <!DOCTYPE html>
  41. <html lang="zh-CN">
  42. <head>
  43. <meta charset="UTF-8">
  44. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  45. <title>厦门市文化遗产保护中心 - <?php echo $queryChannel; ?></title>
  46. <link rel="stylesheet" href="/css/fonts.css">
  47. <link rel="stylesheet" href="/css/fontawesome.min.css">
  48. <link rel="stylesheet" href="/css/bootstrap.min.css">
  49. <link rel="stylesheet" href="/css/swiper-bundle.min.css">
  50. <link rel="stylesheet" href="/css/style.css">
  51. <script src="/js/jquery-3.7.1.js"></script>
  52. <script src="/js/bootstrap.bundle.js"></script>
  53. <script src="/js/swiper-bundle.min.js"></script>
  54. </head>
  55. <body>
  56. <?php include __DIR__ . '/components/navbar.php'; ?>
  57. <!-- 轮播图 -->
  58. <div class="swiper mySwiper" style="width: 100%; height: 400px;">
  59. <div class="swiper-wrapper">
  60. <?php foreach ($carouselItems as $item): ?>
  61. <div class="swiper-slide">
  62. <img src="<?php echo $item['image']; ?>" alt="<?php echo $item['alt']; ?>" style="width: 100%; height: 100%; object-fit: cover;">
  63. </div>
  64. <?php endforeach; ?>
  65. </div>
  66. <div class="swiper-pagination"></div>
  67. <div class="swiper-button-prev"></div>
  68. <div class="swiper-button-next"></div>
  69. </div>
  70. <!-- 主要内容 -->
  71. <div class="main-content">
  72. <div class="container">
  73. <div class="row">
  74. <!-- 左侧导航 -->
  75. <div class="col-12 col-sm-12 col-md-4 col-lg-3">
  76. <div class="sidebar">
  77. <div class="title">
  78. <h2><?php echo $mainChannelName; ?></h2>
  79. </div>
  80. <ul class="sidebar-menu">
  81. <?php if (!empty($sideMenu)): ?>
  82. <?php foreach ($sideMenu as $item): ?>
  83. <li><a href="?channel=<?php echo urlencode($item['name']); ?>&page=1" class="<?php echo $selectedChannel == $item['name'] ? 'active' : ''; ?>"><?php echo $item['name']; ?><i class="fa fa-arrow-right"></i></a></li>
  84. <?php endforeach; ?>
  85. <?php else: ?>
  86. <li class="no-content">暂无相关子分类</li>
  87. <?php endif; ?>
  88. </ul>
  89. </div>
  90. </div>
  91. <!-- 右侧内容 -->
  92. <div class="col-12 col-sm-12 col-md-8 col-lg-9">
  93. <div class="content">
  94. <div class="section-title">
  95. <h2 class="icon"><?php echo $queryChannel; ?></h2>
  96. <nav aria-label="breadcrumb">
  97. <ol class="breadcrumb">
  98. <li class="breadcrumb-item"><a href="/">首页</a></li>
  99. <li class="breadcrumb-item"><a href="./"><?php echo $mainChannelName; ?></a></li>
  100. <?php if ($selectedChannel): ?>
  101. <li class="breadcrumb-item active" aria-current="page"><?php echo $selectedChannel; ?></li>
  102. <?php endif; ?>
  103. </ol>
  104. </nav>
  105. </div>
  106. <!-- 文章列表 -->
  107. <div class="news-list">
  108. <?php if (!empty($workUpdates)): ?>
  109. <?php foreach ($workUpdates as $item): ?>
  110. <?php
  111. // 确保所有必要字段存在
  112. $title = isset($item['title']) ? $item['title'] : '暂无标题';
  113. $articleId = isset($item['id']) ? $item['id'] : '';
  114. $date = isset($item['createtime']) ? date('Y-m-d', intval($item['createtime'])) : '未知日期';
  115. ?>
  116. <div class="news-item">
  117. <a href="/xinWenXiangQing/?id=<?php echo $articleId; ?>&channel=<?php echo urlencode($queryChannel); ?>" class="title"><?php echo $title; ?></a>
  118. <span class="date"><?php echo $date; ?></span>
  119. </div>
  120. <?php endforeach; ?>
  121. <?php else: ?>
  122. <div class="no-news">暂无相关文章</div>
  123. <?php endif; ?>
  124. </div>
  125. <!-- 分页 -->
  126. <nav aria-label="List Page navigation">
  127. <ul class="pagination mt-4">
  128. <li class="prev"><a href="?channel=<?php echo urlencode($selectedChannel); ?>&page=<?php echo $currentPage > 1 ? $currentPage - 1 : 1; ?>">&lt;</a></li>
  129. <?php for ($i = 1; $i <= $totalPages; $i++): ?>
  130. <li class="<?php echo $i == $currentPage ? 'active' : ''; ?>"><a href="?channel=<?php echo urlencode($selectedChannel); ?>&page=<?php echo $i; ?>"><?php echo $i; ?></a></li>
  131. <?php endfor; ?>
  132. <li class="next"><a href="?channel=<?php echo urlencode($selectedChannel); ?>&page=<?php echo $currentPage < $totalPages ? $currentPage + 1 : $totalPages; ?>">&gt;</a></li>
  133. </ul>
  134. </nav>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. <?php include __DIR__ . '/components/footer.php'; ?>
  141. <script>
  142. $(document).ready(function() {
  143. // 初始化 Swiper
  144. const swiper = new Swiper(".mySwiper", {
  145. slidesPerView: 1,
  146. spaceBetween: 30,
  147. loop: true,
  148. pagination: {
  149. el: ".swiper-pagination",
  150. clickable: true,
  151. },
  152. navigation: {
  153. nextEl: ".swiper-button-next",
  154. prevEl: ".swiper-button-prev",
  155. },
  156. autoplay: {
  157. delay: 5000,
  158. disableOnInteraction: false,
  159. },
  160. });
  161. });
  162. </script>
  163. </body>
  164. </html>