150 lines
8.0 KiB
PHP
150 lines
8.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$search_term = $_GET['search'] ?? '';
|
|
|
|
// Fetch blog posts
|
|
$pdo = db();
|
|
$posts = [];
|
|
try {
|
|
if ($search_term) {
|
|
$stmt = $pdo->prepare("SELECT * FROM blog_posts WHERE title LIKE ? OR content LIKE ? ORDER BY created_at DESC");
|
|
$stmt->execute(['%' . $search_term . '%', '%' . $search_term . '%']);
|
|
$posts = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} else {
|
|
$posts = $pdo->query("SELECT * FROM blog_posts ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
} catch (PDOException $e) {
|
|
error_log('Could not fetch blog posts: ' . $e->getMessage());
|
|
}
|
|
|
|
$project_name = "Blog";
|
|
$project_description = "Read our latest articles.";
|
|
$project_keywords = "blog, articles, finance, web development";
|
|
$project_image_url = "https://project-screens.s3.amazonaws.com/screenshots/30971/app-hero-20251016-105317.png";
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title><?php echo htmlspecialchars($project_name); ?></title>
|
|
<meta name="description" content="<?php echo htmlspecialchars($project_description); ?>">
|
|
<meta name="keywords" content="<?php echo htmlspecialchars($project_keywords); ?>">
|
|
|
|
<!-- Open Graph / Facebook -->
|
|
<meta property="og:type" content="website">
|
|
<meta property="og:title" content="<?php echo htmlspecialchars($project_name); ?>">
|
|
<meta property="og:description" content="<?php echo htmlspecialchars($project_description); ?>">
|
|
<meta property="og:image" content="<?php echo htmlspecialchars($project_image_url); ?>">
|
|
|
|
<!-- Twitter -->
|
|
<meta property="twitter:card" content="summary_large_image">
|
|
<meta property="twitter:title" content="<?php echo htmlspecialchars($project_name); ?>">
|
|
<meta property="twitter:description" content="<?php echo htmlspecialchars($project_description); ?>">
|
|
<meta property="twitter:image" content="<?php echo htmlspecialchars($project_image_url); ?>">
|
|
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
<script src="https://unpkg.com/feather-icons"></script>
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-dark fixed-top">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">Alex</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav ms-auto">
|
|
<li class="nav-item"><a class="nav-link" href="index.php#home">Home</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="index.php#about">About</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="index.php#portfolio">Portfolio</a></li>
|
|
<li class="nav-item"><a class="nav-link active" href="blog.php">Blog</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="index.php#contact">Contact</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="/admin" target="_blank">Admin</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<header class="hero text-center">
|
|
<div class="container">
|
|
<h1 class="display-4">Blog</h1>
|
|
<p class="lead">Read our latest articles.</p>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="container mt-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-8">
|
|
<div class="search-container glass-card p-4 mb-5">
|
|
<form action="blog.php" method="GET">
|
|
<div class="input-group">
|
|
<input type="text" class="form-control form-control-lg" name="search" placeholder="Search for articles..." value="<?php echo htmlspecialchars($search_term); ?>">
|
|
<button class="btn btn-primary" type="submit" id="button-addon2">
|
|
<i data-feather="search" class="align-middle"></i>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<?php if ($search_term && !empty($posts)): ?>
|
|
<h2 class="section-title text-center mb-4">Search Results for "<?php echo htmlspecialchars($search_term); ?>"</h2>
|
|
<?php endif; ?>
|
|
|
|
<?php if (empty($posts)): ?>
|
|
<div class="glass-card text-center p-5">
|
|
<h2 class="mb-3"><?php echo $search_term ? 'No Results Found' : 'Coming Soon'; ?></h2>
|
|
<p class="lead"><?php echo $search_term ? 'Sorry, no articles matched your search. Try another term.' : 'No blog posts have been added yet. Check back soon for insights and articles.'; ?></p>
|
|
<?php if ($search_term): ?>
|
|
<a href="blog.php" class="btn btn-outline-primary mt-3">Back to Blog</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="<?php echo $search_term ? 'search-results-container' : 'blog-listing'; ?>">
|
|
<?php foreach ($posts as $post): ?>
|
|
<?php if ($search_term): ?>
|
|
<div class="search-result-item">
|
|
<a href="post.php?slug=<?php echo htmlspecialchars($post['slug']); ?>" class="text-decoration-none">
|
|
<h4><?php echo htmlspecialchars($post['title']); ?></h4>
|
|
</a>
|
|
<p><?php echo htmlspecialchars(substr(strip_tags($post['content']), 0, 200)); ?>...</p>
|
|
<div class="date">Published on <?php echo date("F j, Y", strtotime($post['created_at'])); ?></div>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="blog-post-preview">
|
|
<h3><?php echo htmlspecialchars($post['title']); ?></h3>
|
|
<div class="date">Published on <?php echo date("F j, Y", strtotime($post['created_at'])); ?></div>
|
|
<p><?php echo htmlspecialchars(substr(strip_tags($post['content']), 0, 150)); ?>...</p>
|
|
<a href="post.php?slug=<?php echo htmlspecialchars($post['slug']); ?>" class="btn btn-outline-primary">Read More <i data-feather="arrow-right" class="align-middle" style="width:16px;"></i></a>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<footer class="text-center">
|
|
<div class="container">
|
|
<div class="mb-3">
|
|
<a href="#" class="text-white mx-2"><i data-feather="twitter"></i></a>
|
|
<a href="#" class="text-white mx-2"><i data-feather="linkedin"></i></a>
|
|
<a href="#" class="text-white mx-2"><i data-feather="github"></i></a>
|
|
</div>
|
|
<p>© <?php echo date("Y"); ?> Alex. All Rights Reserved. | <a href="privacy.php">Privacy Policy</a></p>
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
|
<script>
|
|
feather.replace();
|
|
</script>
|
|
</body>
|
|
</html>
|