tp/public/themes/template3/blog.php
2026-03-20 19:48:32 +08:00

241 lines
9.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
$pageTitle = '新闻中心 - Nova';
$pageDescription = 'Nova Bootstrap Template 的新闻中心页面';
$pageKeywords = 'blog, news, nova';
require_once __DIR__ . '/header.php';
?>
<?php
// 本页使用本地分页:根据 query 参数 ?page=n 只展示 newsList 的切片
$allNewsList = is_array($newsList ?? null) ? $newsList : [];
$currentPage = (int)($_GET['page'] ?? 1);
if ($currentPage < 1) {
$currentPage = 1;
}
$pageSize = 4; // 每页展示 4 条grid 中每条占 col-lg-6所以刚好两行
$totalCount = count($allNewsList);
$totalPages = (int)ceil($totalCount / $pageSize);
if ($totalPages < 1) {
$totalPages = 1;
}
if ($currentPage > $totalPages) {
$currentPage = $totalPages;
}
$newsListForPage = array_slice($allNewsList, ($currentPage - 1) * $pageSize, $pageSize);
?>
<!-- Page Title -->
<div class="page-title dark-background" data-aos="fade" style="background-image: url(<?php echo $baseUrl; ?>/themes/template3/assets/img/blog-page-title-bg.jpg);">
<div class="container">
<h1>新闻中心</h1>
<nav class="breadcrumbs">
<ol>
<li><a href="<?php echo $baseUrl; ?>/">主页</a></li>
<li class="current">新闻中心</li>
</ol>
</nav>
</div>
</div><!-- End Page Title -->
<div class="container">
<div class="row">
<div class="col-lg-8">
<!-- Blog Posts Section -->
<section id="blog-posts" class="blog-posts section">
<div class="container">
<div class="row gy-4">
<?php if (!empty($newsList)): ?>
<?php foreach ($newsListForPage as $i => $item): ?>
<?php
$title = $item['title'] ?? '无标题';
$author = $item['author'] ?? '';
$category = $item['category'] ?? ($item['category_name'] ?? '');
$publishDateRaw = $item['publish_date'] ?? '';
$postDate = !empty($publishDateRaw) ? date('Y年m月d日', strtotime($publishDateRaw)) : '';
$thumbUrl = $item['thumb'] ?? ($item['image'] ?? '');
if (!empty($thumbUrl)) {
if (strpos($thumbUrl, 'http') === 0) {
$imgSrc = $thumbUrl;
} elseif (strpos($thumbUrl, '/') === 0) {
$imgSrc = $apiUrl . $thumbUrl;
} else {
$imgSrc = $apiUrl . '/' . $thumbUrl;
}
} else {
$imgIndex = ($i % 6) + 1; // blog-1.jpg ~ blog-6.jpg
$imgSrc = $baseUrl . "/themes/template3/assets/img/blog/blog-{$imgIndex}.jpg";
}
$articleUrl = $apiUrl . '/article_detail/' . ($item['id'] ?? 0);
?>
<div class="col-lg-6">
<article>
<div class="post-img">
<img src="<?php echo htmlspecialchars($imgSrc); ?>" alt="" class="img-fluid">
</div>
<p class="post-category"><?php echo htmlspecialchars($category); ?></p>
<h2 class="title">
<a href="<?php echo htmlspecialchars($articleUrl); ?>">
<?php echo htmlspecialchars($title); ?>
</a>
</h2>
<div class="d-flex align-items-center">
<img src="<?php echo $baseUrl; ?>/themes/template3/assets/img/blog/blog-author.jpg" alt="" class="img-fluid post-author-img flex-shrink-0">
<div class="post-meta">
<p class="post-author"><?php echo htmlspecialchars($author); ?></p>
<p class="post-date">
<time datetime="<?php echo htmlspecialchars($publishDateRaw); ?>">
<?php echo htmlspecialchars($postDate); ?>
</time>
</p>
</div>
</div>
</article>
</div><!-- End post list item -->
<?php endforeach; ?>
<?php else: ?>
<div class="col-12 text-center">
<p>暂无新闻数据</p>
</div>
<?php endif; ?>
</div>
</div>
</section><!-- /Blog Posts Section -->
<!-- Blog Pagination Section -->
<section id="blog-pagination" class="blog-pagination section">
<div class="container">
<div class="d-flex justify-content-center">
<ul>
<?php
$prevPage = max(1, $currentPage - 1);
$nextPage = min($totalPages, $currentPage + 1);
$showMax = 10;
$showTotal = min($totalPages, $showMax);
?>
<li><a href="<?php echo $baseUrl; ?>/blog?page=<?php echo $prevPage; ?>"><i class="bi bi-chevron-left"></i></a></li>
<?php for ($p = 1; $p <= $showTotal; $p++): ?>
<li>
<a
href="<?php echo $baseUrl; ?>/blog?page=<?php echo $p; ?>"
<?php echo ($p === $currentPage) ? 'class="active"' : ''; ?>
>
<?php echo $p; ?>
</a>
</li>
<?php endfor; ?>
<li><a href="<?php echo $baseUrl; ?>/blog?page=<?php echo $nextPage; ?>"><i class="bi bi-chevron-right"></i></a></li>
</ul>
</div>
</div>
</section><!-- /Blog Pagination Section -->
</div>
<div class="col-lg-4 sidebar">
<div class="widgets-container">
<!-- Search Widget -->
<div class="search-widget widget-item">
<h3 class="widget-title">搜索</h3>
<form action="">
<input type="text">
<button type="submit" title="Search"><i class="bi bi-search"></i></button>
</form>
</div><!--/Search Widget -->
<!-- Categories Widget -->
<div class="categories-widget widget-item">
<h3 class="widget-title">分类</h3>
<ul class="mt-3">
<li><a href="#">General <span>(25)</span></a></li>
<li><a href="#">Lifestyle <span>(12)</span></a></li>
<li><a href="#">Travel <span>(5)</span></a></li>
<li><a href="#">Design <span>(22)</span></a></li>
<li><a href="#">Creative <span>(8)</span></a></li>
<li><a href="#">Educaion <span>(14)</span></a></li>
</ul>
</div><!--/Categories Widget -->
<!-- Recent Posts Widget -->
<div class="recent-posts-widget widget-item">
<h3 class="widget-title">最新文章</h3>
<div class="post-item">
<img src="<?php echo $baseUrl; ?>/themes/template3/assets/img/blog/blog-recent-1.jpg" alt="" class="flex-shrink-0">
<div>
<h4><a href="<?php echo $baseUrl; ?>/blog-details">Nihil blanditiis at in nihil autem</a></h4>
<time datetime="2020-01-01">Jan 1, 2020</time>
</div>
</div><!-- End recent post item-->
<div class="post-item">
<img src="<?php echo $baseUrl; ?>/themes/template3/assets/img/blog/blog-recent-2.jpg" alt="" class="flex-shrink-0">
<div>
<h4><a href="<?php echo $baseUrl; ?>/blog-details">Quidem autem et impedit</a></h4>
<time datetime="2020-01-01">Jan 1, 2020</time>
</div>
</div><!-- End recent post item-->
<div class="post-item">
<img src="<?php echo $baseUrl; ?>/themes/template3/assets/img/blog/blog-recent-3.jpg" alt="" class="flex-shrink-0">
<div>
<h4><a href="<?php echo $baseUrl; ?>/blog-details">Id quia et et ut maxime similique occaecati ut</a></h4>
<time datetime="2020-01-01">Jan 1, 2020</time>
</div>
</div><!-- End recent post item-->
<div class="post-item">
<img src="<?php echo $baseUrl; ?>/themes/template3/assets/img/blog/blog-recent-4.jpg" alt="" class="flex-shrink-0">
<div>
<h4><a href="<?php echo $baseUrl; ?>/blog-details">Laborum corporis quo dara net para</a></h4>
<time datetime="2020-01-01">Jan 1, 2020</time>
</div>
</div><!-- End recent post item-->
<div class="post-item">
<img src="<?php echo $baseUrl; ?>/themes/template3/assets/img/blog/blog-recent-5.jpg" alt="" class="flex-shrink-0">
<div>
<h4><a href="<?php echo $baseUrl; ?>/blog-details">Et dolores corrupti quae illo quod dolor</a></h4>
<time datetime="2020-01-01">Jan 1, 2020</time>
</div>
</div><!-- End recent post item-->
</div><!--/Recent Posts Widget -->
</div>
</div>
</div>
</div>
</main>
<?php require_once __DIR__ . '/footer.php'; ?>