xinWenXiangQing.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. // 引入公共查询类
  3. require_once 'CommonQuery.php';
  4. // 获取URL参数中的文章ID
  5. $articleId = isset($_GET['id']) ? $_GET['id'] : '';
  6. // 默认频道名称
  7. $defaultChannel = '党建工作';
  8. $currentChannel = $defaultChannel;
  9. // 如果有ID,则使用getContentById函数查询数据
  10. if (!empty($articleId)) {
  11. $newsData = getContentById($articleId);
  12. }
  13. // 如果查询失败或没有ID,使用默认数据
  14. if (!$newsData) {
  15. $newsData = [
  16. "title" => "文章不存在",
  17. "content" => "抱歉,您查看的文章不存在或已被删除。",
  18. "date" => date('Y-m-d'),
  19. "views" => 0
  20. ];
  21. } else {
  22. // 确保必要字段存在
  23. $newsData['title'] = isset($newsData['title']) ? $newsData['title'] : (isset($newsData['subject']) ? $newsData['subject'] : '无标题');
  24. $newsData['content'] = isset($newsData['content']) ? $newsData['content'] : '无内容';
  25. $newsData['date'] = isset($newsData['date']) ? $newsData['date'] : (isset($newsData['createtime']) ? date('Y-m-d', strtotime($newsData['createtime'])) : date('Y-m-d'));
  26. $newsData['views'] = isset($newsData['views']) ? $newsData['views'] : 0;
  27. // 如果有channel_id,尝试获取频道名称
  28. if (isset($newsData['channel_id'])) {
  29. try {
  30. $channel = Db::table('pr_cms_channel')
  31. ->where('id', $newsData['channel_id'])
  32. ->first(['name']);
  33. if ($channel && !empty($channel['name'])) {
  34. $currentChannel = $channel['name'];
  35. }
  36. } catch (Exception $e) {
  37. // 发生异常时保持默认频道名称
  38. }
  39. }
  40. }
  41. // 轮播图数据 - 使用当前频道名称
  42. $carouselItems = [
  43. [
  44. "image" => "/images/test-header-2.png",
  45. "alt" => $currentChannel
  46. ]
  47. ];
  48. ?>
  49. <!DOCTYPE html>
  50. <html lang="zh-CN">
  51. <head>
  52. <meta charset="UTF-8">
  53. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  54. <title>厦门市文化遗产保护中心 - <?php echo $newsData['title']; ?></title>
  55. <link rel="stylesheet" href="/css/fonts.css">
  56. <link rel="stylesheet" href="/css/fontawesome.min.css">
  57. <link rel="stylesheet" href="/css/bootstrap.min.css">
  58. <link rel="stylesheet" href="/css/swiper-bundle.min.css">
  59. <link rel="stylesheet" href="/css/style.css">
  60. <script src="/js/jquery-3.7.1.js"></script>
  61. <script src="/js/bootstrap.bundle.js"></script>
  62. <script src="/js/swiper-bundle.min.js"></script>
  63. </head>
  64. <body>
  65. <?php include __DIR__ . '/components/navbar.php'; ?>
  66. <!-- 轮播图 -->
  67. <div class="swiper mySwiper" style="width: 100%; height: 400px;">
  68. <div class="swiper-wrapper">
  69. <?php foreach ($carouselItems as $item): ?>
  70. <div class="swiper-slide">
  71. <img src="<?php echo $item['image']; ?>" alt="<?php echo $item['alt']; ?>" style="width: 100%; height: 100%; object-fit: cover;">
  72. </div>
  73. <?php endforeach; ?>
  74. </div>
  75. <div class="swiper-pagination"></div>
  76. <div class="swiper-button-prev"></div>
  77. <div class="swiper-button-next"></div>
  78. </div>
  79. <!-- 主要内容 -->
  80. <div class="main-content">
  81. <div class="container">
  82. <div class="row">
  83. <!-- 左侧导航 -->
  84. <div class="col col-sm-12 col-md-3 col-lg-3">
  85. <div class="sidebar">
  86. <div class="title">
  87. <h2><?php echo $currentChannel; ?></h2>
  88. </div>
  89. <ul class="sidebar-menu">
  90. <li><a href="#"><?php echo $currentChannel; ?><i class="fa fa-arrow-right"></i></a></li>
  91. <li><a href="#">党建要闻<i class="fa fa-arrow-right"></i></a></li>
  92. </ul>
  93. </div>
  94. </div>
  95. <!-- 右侧内容 -->
  96. <div class="col col-sm-12 col-md-9 col-lg-9">
  97. <div class="content">
  98. <div class="section-title">
  99. <h2 class="icon"><?php echo $currentChannel; ?></h2>
  100. <nav aria-label="breadcrumb">
  101. <ol class="breadcrumb">
  102. <li class="breadcrumb-item"><a href="/">首页</a></li>
  103. <li class="breadcrumb-item active" aria-current="page"><?php echo $currentChannel; ?></li>
  104. </ol>
  105. </nav>
  106. </div>
  107. <div class="news-detail">
  108. <h1><?php echo $newsData['title']; ?></h1>
  109. <div class="times">
  110. <p class="date">时间:<?php echo $newsData['date']; ?></p>
  111. <p class="views">浏览量: <?php echo $newsData['views']; ?> </p>
  112. </div>
  113. <div class="content-text">
  114. <?php echo $newsData['content']; ?>
  115. </div>
  116. </div>
  117. <!-- 相关文章 -->
  118. <?php if (isset($newsData['channel_id'])): ?>
  119. <div class="related-news">
  120. <h3>相关文章</h3>
  121. <ul>
  122. <?php
  123. try {
  124. // 获取相同频道的5篇文章(排除当前文章)
  125. $relatedArticles = Db::table('pr_cms_archives')
  126. ->where('channel_id', $newsData['channel_id'])
  127. ->where('id', '!=', $articleId)
  128. ->limit(5)
  129. ->order('id', 'desc')
  130. ->get(['id', 'title', 'createtime']);
  131. if ($relatedArticles) {
  132. foreach ($relatedArticles as $article) {
  133. $articleDate = isset($article['createtime']) ? date('Y-m-d', strtotime($article['createtime'])) : '';
  134. echo "<li><a href='xinWenXiangQing.php?id={$article['id']}'>{$article['title']}</a><span>{$articleDate}</span></li>";
  135. }
  136. } else {
  137. echo "<li>暂无相关文章</li>";
  138. }
  139. } catch (Exception $e) {
  140. echo "<li>获取相关文章失败</li>";
  141. }
  142. ?>
  143. </ul>
  144. </div>
  145. <?php endif; ?>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. <?php include __DIR__ . '/components/footer.php'; ?>
  152. <script>
  153. $(document).ready(function() {
  154. // 初始化 Swiper
  155. const swiper = new Swiper(".mySwiper", {
  156. slidesPerView: 1,
  157. spaceBetween: 30,
  158. loop: true,
  159. pagination: {
  160. el: ".swiper-pagination",
  161. clickable: true,
  162. },
  163. navigation: {
  164. nextEl: ".swiper-button-next",
  165. prevEl: ".swiper-button-prev",
  166. },
  167. autoplay: {
  168. delay: 5000,
  169. disableOnInteraction: false,
  170. },
  171. });
  172. });
  173. </script>
  174. </body>
  175. </html>