| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <?php
- // 引入公共查询类
- require_once 'CommonQuery.php';
- // 获取URL参数中的文章ID
- $articleId = isset($_GET['id']) ? $_GET['id'] : '';
- // 默认频道名称
- $defaultChannel = '党建工作';
- $currentChannel = $defaultChannel;
- // 如果有ID,则使用getContentById函数查询数据
- if (!empty($articleId)) {
- $newsData = getContentById($articleId);
- }
- // 如果查询失败或没有ID,使用默认数据
- if (!$newsData) {
- $newsData = [
- "title" => "文章不存在",
- "content" => "抱歉,您查看的文章不存在或已被删除。",
- "date" => date('Y-m-d'),
- "views" => 0
- ];
- } else {
- // 确保必要字段存在
- $newsData['title'] = isset($newsData['title']) ? $newsData['title'] : (isset($newsData['subject']) ? $newsData['subject'] : '无标题');
- $newsData['content'] = isset($newsData['content']) ? $newsData['content'] : '无内容';
- $newsData['date'] = isset($newsData['date']) ? $newsData['date'] : (isset($newsData['createtime']) ? date('Y-m-d', intval($newsData['createtime'])) : date('Y-m-d'));
- $newsData['views'] = isset($newsData['views']) ? $newsData['views'] : 0;
-
- // 如果有channel_id,尝试获取频道名称
- if (isset($newsData['channel_id'])) {
- try {
- $channel = Db::table('pr_cms_channel')
- ->where('id', $newsData['channel_id'])
- ->first(['name']);
- if ($channel && !empty($channel['name'])) {
- $currentChannel = $channel['name'];
- }
- } catch (Exception $e) {
- // 发生异常时保持默认频道名称
- }
- }
- }
- // 轮播图数据 - 使用当前频道名称
- $carouselItems = [
- [
- "image" => "/images/test-header-2.png",
- "alt" => $currentChannel
- ]
- ];
- ?>
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>厦门市文化遗产保护中心 - <?php echo $newsData['title']; ?></title>
- <link rel="stylesheet" href="/css/fonts.css">
- <link rel="stylesheet" href="/css/fontawesome.min.css">
- <link rel="stylesheet" href="/css/bootstrap.min.css">
- <link rel="stylesheet" href="/css/swiper-bundle.min.css">
- <link rel="stylesheet" href="/css/style.css">
- <script src="/js/jquery-3.7.1.js"></script>
- <script src="/js/bootstrap.bundle.js"></script>
- <script src="/js/swiper-bundle.min.js"></script>
- </head>
- <body>
- <?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>
- <div class="swiper-pagination"></div>
- <div class="swiper-button-prev"></div>
- <div class="swiper-button-next"></div>
- </div>
- <!-- 主要内容 -->
- <div class="main-content">
- <div class="container">
- <div class="row">
- <!-- 左侧导航 -->
- <div class="col-12 col-sm-12 col-md-4 col-lg-3">
- <div class="sidebar">
- <div class="title">
- <h2><?php echo $currentChannel; ?></h2>
- </div>
- <ul class="sidebar-menu">
- <li><a href="#"><?php echo $currentChannel; ?><i class="fa fa-arrow-right"></i></a></li>
- </ul>
- </div>
- </div>
-
- <!-- 右侧内容 -->
- <div class="col-12 col-sm-12 col-md-8 col-lg-9">
- <div class="content">
- <div class="section-title">
- <h2 class="icon"><?php echo $currentChannel; ?></h2>
-
- <nav aria-label="breadcrumb">
- <ol class="breadcrumb">
- <li class="breadcrumb-item"><a href="/">首页</a></li>
- <li class="breadcrumb-item active" aria-current="page"><?php echo $currentChannel; ?></li>
- </ol>
- </nav>
- </div>
-
- <div class="news-detail">
- <h1><?php echo $newsData['title']; ?></h1>
- <div class="times">
- <p class="date">时间:<?php echo $newsData['date']; ?></p>
- <p class="views">浏览量: <?php echo $newsData['views']; ?> </p>
- </div>
- <div class="content-text">
- <?php echo $newsData['content']; ?>
- </div>
- </div>
-
- <!-- 相关文章 -->
- <?php if (isset($newsData['channel_id'])): ?>
- <div class="related-news mt-3">
- <h3>相关文章</h3>
- <ul>
- <?php
- try {
- // 获取相同频道的5篇文章(排除当前文章)
- $relatedArticles = Db::table('pr_cms_archives')
- ->where('channel_id', $newsData['channel_id'])
- ->where('id', '!=', $articleId)
- ->limit(5)
- ->order('id', 'desc')
- ->get(['id', 'title', 'createtime']);
-
- if ($relatedArticles) {
- foreach ($relatedArticles as $article) {
- $articleDate = isset($article['createtime']) ? date('Y-m-d', intval($article['createtime'])) : '';
- echo "<li><a href='/xinWenXiangQing/?id={$article['id']}'>{$article['title']}</a><span>{$articleDate}</span></li>";
- }
- } else {
- echo "<li>暂无相关文章</li>";
- }
- } catch (Exception $e) {
- echo "<li>暂无相关文章</li>";
- }
- ?>
- </ul>
- </div>
- <?php endif; ?>
- </div>
- </div>
- </div>
- </div>
- </div>
- <?php include __DIR__ . '/components/footer.php'; ?>
-
- <script>
- $(document).ready(function() {
- // 初始化 Swiper
- const swiper = new Swiper(".mySwiper", {
- slidesPerView: 1,
- spaceBetween: 30,
- loop: true,
- pagination: {
- el: ".swiper-pagination",
- clickable: true,
- },
- navigation: {
- nextEl: ".swiper-button-next",
- prevEl: ".swiper-button-prev",
- },
- autoplay: {
- delay: 5000,
- disableOnInteraction: false,
- },
- });
- });
- </script>
- </body>
- </html>
|