<?php

include("admin/connection.php");
include('include/header.php');
?>
<?php
$slug = $_GET['slug'];
$ser = mysqli_query($con, "SELECT * FROM `blog` where slug='$slug'");
while ($row = mysqli_fetch_array($ser)) {
    $title = $row['title'];
    $short_des = $row['short_des'];
    $slug = $row['slug'];
    $Image = $row['Image'];
    $id = $row['id'];
    $description = $row['description'];
}
?>
<div class="breadcumb-wrapper" data-bg-src="<?php path(); ?>/assets/img/blog/breadcrumb-bg.jpg">
    <div class="container">
        <div class="breadcumb-content">
            <h1 class="breadcumb-title"><?php echo $title; ?></h1>
            <ul class="breadcumb-menu">
                <li><a href="<?php path(); ?>/index.php">Home</a></li>
                <li><?php echo $title; ?></li>
            </ul>
        </div>
    </div>
</div>
<section class="th-blog-wrapper blog-details space-top space-extra-bottom">
    <div class="container">
        <div class="row">
            <div class="col-md-12 col-lg-8">
                <?php
                // Fetch service details by ID (make sure $id is defined earlier)
                $ser = mysqli_query($con, "SELECT * FROM `blog` WHERE id = '$id'");
                if ($row = mysqli_fetch_array($ser)) {
                    $image = $row['Image'];
                    $title = $row['title'];
                    $short_des = $row['short_des'];
                    $description = $row['description'];
                ?>
                    <div class="th-blog blog-single">
                        <div class="blog-img">
                            <img src="<?php path(); ?>/admin/assets/images/blog/<?php echo htmlspecialchars($image); ?>" alt="Image">
                        </div>
                        <div class="blog-content">

                            <h2 class="blog-title"><?php echo $title; ?></h2>
                            <p><?php echo $description; ?></p>

                            <blockquote>
                                <p><?php echo $short_des; ?></p>
                            </blockquote>



                        </div>
                    </div>

            </div>
        <?php
                }
        ?>
        <div class="col-md-12 col-lg-4">
            <aside class="sidebar-area">

                <div class="widget">
                    <h3 class="widget_title">All Blogs </h3>
                    <div class="recent-post-wrap featured-listing">
                        <?php

                        $services = mysqli_query($con, "SELECT slug, title, Image FROM `blog` ORDER BY id DESC");
                        while ($s = mysqli_fetch_array($services)) {
                            $slug = $s['slug'];
                            $title = $s['title'];
                            $Image = $s['Image'];
                        ?>
                            <div class="recent-post">
                                <div class="media-img">
                                    <a href="<?php path(); ?>/blog-details.php?slug=<?php echo $slug; ?>">
                                        <img src="<?php path(); ?>/admin/assets/images/blog/<?php echo $Image; ?>" alt="<?php echo htmlspecialchars($title); ?>">
                                    </a>
                                </div>
                                <div class="media-body">
                                    <h4 class="post-title">
                                        <a class="text-inherit" href="<?php path(); ?>/blog-details.php?slug=<?php echo $slug; ?>">
                                            <?php echo htmlspecialchars($title); ?>
                                        </a>
                                    </h4>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </div>
                

            </aside>
        </div>
        </div>
    </div>
</section>
<?php
include("include/footer.php");
?>