/
home
/
wellcas2
/
public_html
/
Upload File
HOME
<?php $pageTitle = "Blog & Insights | Wellcash Debt Collectors"; $activePage = "blog"; require_once 'config/helpers.php'; // 1. Fetch entries from the `posts` table if it exists $posts = db_all($pdo, 'posts', 'created_at DESC'); // 2. Fetch entries from the `blog` table $blogPosts = db_all($pdo, 'blog', 'updated_at DESC'); // 3. Normalize and combine both datasets into a unified array $allPosts = []; if (!empty($posts)) { foreach ($posts as $p) { $allPosts[] = [ 'id' => $p['id'], 'title' => $p['title'] ?? $p['post_title'] ?? 'Untitled Article', 'desc' => $p['excerpt'] ?? $p['content'] ?? $p['description'] ?? '', 'image' => $p['image'] ?? $p['ufile'] ?? $p['featured_image'] ?? '', 'date' => $p['created_at'] ?? $p['updated_at'] ?? date('Y-m-d H:i:s'), 'type' => 'post' ]; } } if (!empty($blogPosts)) { foreach ($blogPosts as $b) { $allPosts[] = [ 'id' => $b['id'], 'title' => $b['blog_title'] ?? 'Untitled Article', 'desc' => $b['blog_desc'] ?? '', 'image' => $b['ufile'] ?? '', 'date' => $b['updated_at'] ?? date('Y-m-d H:i:s'), 'type' => 'blog' ]; } } // 4. Sort the merged posts by date (newest first) usort($allPosts, function($a, $b) { return strtotime($b['date']) - strtotime($a['date']); }); include 'template/header.php'; ?> <!-- Hero Section --> <section class="page-hero"> <div class="container"> <div class="breadcrumb"> <a href="index.php">Home</a> <span>→</span> <span>Blog & Insights</span> </div> <h1>Our <span class="text-red">Insights</span></h1> <p>Expert articles, compliance guides, and financial advice on credit control and debt recovery.</p> </div> </section> <!-- Blog Posts Feed Grid --> <section class="section"> <div class="container"> <div class="row-table" style="gap: 0; margin-bottom: 30px;"> <?php if (!empty($allPosts)): ?> <?php foreach ($allPosts as $post): ?> <!-- Article Card --> <div class="col-table-3 reveal" style="margin-bottom: 40px;"> <div style="background-color: #fff; border-radius: 8px; border: 1px solid #eee; overflow: hidden; height: 100%; display: flex; flex-direction: column; box-shadow: 0 4px 15px rgba(0,0,0,0.02); transition: transform 0.2s ease;"> <!-- Post Image --> <div style="height: 200px; background: #eee url('<?php echo htmlspecialchars(upload_path($post['image'])); ?>') no-repeat center center; background-size: cover;"></div> <!-- Post Content --> <div style="padding: 25px; display: flex; flex-direction: column; flex-grow: 1;"> <div style="font-size: 12px; color: #888; margin-bottom: 10px; display: flex; gap: 15px;"> <span><i class="fa-solid fa-calendar-days"></i> <?php echo date('M d, Y', strtotime($post['date'])); ?></span> </div> <h3 style="font-size: 18px; margin: 0 0 12px 0; line-height: 1.4; color: var(--brand-black);"> <?php echo htmlspecialchars($post['title']); ?> </h3> <p style="font-size: 14px; color: #666; line-height: 1.6; margin-bottom: 20px; flex-grow: 1;"> <?php echo htmlspecialchars(mb_strimwidth($post['desc'], 0, 130, '...')); ?> </p> <a href="<?php echo ($post['type'] === 'post') ? 'blog-single.php?id=' : 'blog-single.php?id='; ?><?php echo (int)$post['id']; ?>" class="text-red" style="font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; font-size: 14px;"> Read Article <i class="fa-solid fa-arrow-right-long"></i> </a> </div> </div> </div> <?php endforeach; ?> <?php else: ?> <!-- Fallback in case there are zero posts in phpMyAdmin --> <div style="width: 100%; text-align: center; padding: 50px 0;"> <i class="fa-regular fa-folder-open" style="font-size: 48px; color: #ccc; margin-bottom: 15px;"></i> <p style="color: #666;">No posts published yet. Check back soon!</p> </div> <?php endif; ?> </div> </div> </section> <?php include 'template/footer.php'; ?>