Files
ai-institute/blog.php
T
2026-11-18 15:40:30 +05:45

92 lines
3.8 KiB
PHP

<?php
require_once __DIR__ . '/includes/data.php';
$pageTitle = 'Blog | AI Institute';
$pageDescription = 'Guides, tutorials and ideas to help you learn AI tools and use them in your work, business and everyday life.';
$activePage = 'blog';
$posts = $posts ?? [];
$postsPerPage = 9;
$totalPosts = count($posts);
$totalPages = $totalPosts > 0 ? (int) ceil($totalPosts / $postsPerPage) : 1;
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
if ($page < 1) {
$page = 1;
}
if ($page > $totalPages) {
$page = $totalPages;
}
$offset = ($page - 1) * $postsPerPage;
$pagePosts = array_slice($posts, $offset, $postsPerPage);
require __DIR__ . '/includes/header.php';
?>
<main id="main-content" class="blog">
<!-- ===== BLOG HERO ===== -->
<section class="blog-hero cert-hero section">
<div class="container">
<div class="section__head reveal">
<span class="eyebrow">Blog</span>
<h1 class="section__title">Insights on practical AI.</h1>
<p class="section__lead">Guides, tutorials and ideas to help you learn AI tools and use them in your work, business and everyday life.</p>
</div>
</div>
</section>
<!-- ===== BLOG POSTS ===== -->
<section class="section blog-posts" id="posts">
<div class="container">
<div class="blog-grid">
<?php foreach ($pagePosts as $post): ?>
<article class="blog-card card reveal">
<div class="blog-card__media">
<img
class="blog-card__img"
src="<?= e($post['image'] ?? '') ?>"
alt="<?= e($post['alt'] ?? '') ?>"
width="1200"
height="675"
loading="lazy"
>
</div>
<div class="blog-card__body">
<h2 class="blog-card__title">
<a class="blog-card__link" href="blog-detail.php?slug=<?= e($post['slug'] ?? '') ?>"><?= e($post['title'] ?? '') ?></a>
</h2>
<p class="blog-card__meta"><?= e($post['date'] ?? '') ?> · <?= (int) ($post['read_time'] ?? 0) ?> min read</p>
<p class="blog-card__excerpt"><?= e($post['excerpt'] ?? '') ?></p>
</div>
</article>
<?php endforeach; ?>
</div>
<nav class="pagination" aria-label="Blog pagination">
<?php if ($page <= 1): ?>
<span class="pagination__link is-disabled" aria-disabled="true">First</span>
<?php else: ?>
<a class="pagination__link" href="blog.php?page=1#posts">First</a>
<?php endif; ?>
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
<?php if ($i === $page): ?>
<a class="pagination__link is-active" href="blog.php?page=<?= $i ?>#posts" aria-current="page"><?= $i ?></a>
<?php else: ?>
<a class="pagination__link" href="blog.php?page=<?= $i ?>#posts"><?= $i ?></a>
<?php endif; ?>
<?php endfor; ?>
<?php if ($page >= $totalPages): ?>
<span class="pagination__link is-disabled" aria-disabled="true">Last</span>
<?php else: ?>
<a class="pagination__link" href="blog.php?page=<?= $totalPages ?>#posts">Last</a>
<?php endif; ?>
</nav>
</div>
</section>
</main>
<?php require __DIR__ . '/includes/footer.php'; ?>