xinWenXiangQing.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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', intval($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 = getBannerData();
  43. ?>
  44. <!DOCTYPE html>
  45. <html lang="zh-CN">
  46. <head>
  47. <meta charset="UTF-8">
  48. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  49. <title>厦门市文化遗产保护中心 - <?php echo $newsData['title']; ?></title>
  50. <link rel="stylesheet" href="/css/fonts.css">
  51. <link rel="stylesheet" href="/css/fontawesome.min.css">
  52. <link rel="stylesheet" href="/css/bootstrap.min.css">
  53. <link rel="stylesheet" href="/css/swiper-bundle.min.css">
  54. <link rel="stylesheet" href="/css/style.css">
  55. <script src="/js/jquery-3.7.1.js"></script>
  56. <script src="/js/bootstrap.bundle.js"></script>
  57. <script src="/js/swiper-bundle.min.js"></script>
  58. </head>
  59. <body>
  60. <?php include __DIR__ . '/components/navbar.php'; ?>
  61. <!-- 轮播图 -->
  62. <div class="swiper mySwiper" style="width: 100%; height: 400px;">
  63. <div class="swiper-wrapper">
  64. <?php foreach ($carouselItems as $item): ?>
  65. <div class="swiper-slide">
  66. <img src="<?php echo $item['image']; ?>" alt="<?php echo $item['alt']; ?>" style="width: 100%; height: 100%; object-fit: cover;">
  67. </div>
  68. <?php endforeach; ?>
  69. </div>
  70. <div class="swiper-pagination"></div>
  71. <div class="swiper-button-prev"></div>
  72. <div class="swiper-button-next"></div>
  73. </div>
  74. <!-- 主要内容 -->
  75. <div class="main-content">
  76. <div class="container">
  77. <div class="row">
  78. <!-- 左侧导航 -->
  79. <div class="col-12 col-sm-12 col-md-4 col-lg-3">
  80. <div class="sidebar">
  81. <div class="title">
  82. <h2><?php echo $currentChannel; ?></h2>
  83. </div>
  84. <ul class="sidebar-menu">
  85. <li><a href="#"><?php echo $currentChannel; ?><i class="fa fa-arrow-right"></i></a></li>
  86. </ul>
  87. </div>
  88. </div>
  89. <!-- 右侧内容 -->
  90. <div class="col-12 col-sm-12 col-md-8 col-lg-9">
  91. <div class="content">
  92. <div class="section-title">
  93. <h2 class="icon"><?php echo $currentChannel; ?></h2>
  94. <nav aria-label="breadcrumb">
  95. <ol class="breadcrumb">
  96. <li class="breadcrumb-item"><a href="/">首页</a></li>
  97. <li class="breadcrumb-item active" aria-current="page"><?php echo $currentChannel; ?></li>
  98. </ol>
  99. </nav>
  100. </div>
  101. <div class="news-detail">
  102. <h1><?php echo $newsData['title']; ?></h1>
  103. <div class="times">
  104. <p class="date">时间:<?php echo $newsData['date']; ?></p>
  105. <p class="views">浏览量: <?php echo $newsData['views']; ?> </p>
  106. </div>
  107. <div class="content-text">
  108. <?php echo $newsData['content']; ?>
  109. </div>
  110. </div>
  111. <!-- 相关文章 -->
  112. <?php if (isset($newsData['channel_id'])): ?>
  113. <div class="related-news mt-3">
  114. <h3>相关文章</h3>
  115. <ul>
  116. <?php
  117. try {
  118. // 获取相同频道的5篇文章(排除当前文章)
  119. $relatedArticles = Db::table('pr_cms_archives')
  120. ->where('channel_id', $newsData['channel_id'])
  121. ->where('id', '!=', $articleId)
  122. ->limit(5)
  123. ->order('id', 'desc')
  124. ->get(['id', 'title', 'createtime']);
  125. if ($relatedArticles) {
  126. foreach ($relatedArticles as $article) {
  127. $articleDate = isset($article['createtime']) ? date('Y-m-d', intval($article['createtime'])) : '';
  128. echo "<li><a href='/xinWenXiangQing/?id={$article['id']}'>{$article['title']}</a><span>{$articleDate}</span></li>";
  129. }
  130. } else {
  131. echo "<li>暂无相关文章</li>";
  132. }
  133. } catch (Exception $e) {
  134. echo "<li>暂无相关文章</li>";
  135. }
  136. ?>
  137. </ul>
  138. </div>
  139. <?php endif; ?>
  140. </div>
  141. </div>
  142. </div>
  143. </div>
  144. </div>
  145. <?php include __DIR__ . '/components/footer.php'; ?>
  146. <script>
  147. $(document).ready(function() {
  148. // 初始化 Swiper
  149. const swiper = new Swiper(".mySwiper", {
  150. slidesPerView: 1,
  151. spaceBetween: 30,
  152. loop: true,
  153. pagination: {
  154. el: ".swiper-pagination",
  155. clickable: true,
  156. },
  157. navigation: {
  158. nextEl: ".swiper-button-next",
  159. prevEl: ".swiper-button-prev",
  160. },
  161. autoplay: {
  162. delay: 5000,
  163. disableOnInteraction: false,
  164. },
  165. });
  166. });
  167. </script>
  168. </body>
  169. </html>