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

162 lines
6.1 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 = 8; // 每页展示 8 条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-12">
<!-- 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";
}
// 文章详情链接必须走前台域名,否则 api.yunzer.cn 上租户解析不生效
$articleUrl = $baseUrl . '/article_detail/' . ($item['id'] ?? 0);
?>
<div class="col-lg-3 col-md-6">
<article>
<div class="post-media">
<img src="<?php echo htmlspecialchars($imgSrc); ?>" alt="" class="post-media-img" />
</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>
</div>
</main>
<?php require_once __DIR__ . '/footer.php'; ?>