<?php require_once('includes/cmain.inc.php');?>
<?php 
$url = explode('/', rtrim($_SERVER["REQUEST_URI"],"/")); 
$count=count($url);
$urltag=str_replace('-',' ',trim($url[3]));
$menuurl = ucwords(str_replace('-', ' ',$url[$count-1]));
$q="SELECT * FROM `tbl_blog` WHERE heading='$menuurl' AND status='1'";

//$a=SITE_WS_PATH.'/'.$url[1].'/'.$url[2];

$sqlmenu=db_query("SELECT * FROM `tbl_blog` WHERE heading='$menuurl' AND status='1'");
$menu=mysqli_fetch_array($sqlmenu);

$newq =$menu['heading'] ?? ''; 
//print_r($newq);exit();
if($newq == NULL)
{

include('404page.php'); exit;
}
else
{
$titlenot= $menu['heading'];
$descriptionnot= $menu['description'];
$keywordnot= $menu['keyword'];
$urlkb=$url[2];
$meta_url=$a;
//$meta_image=SITE_WS_PATH."/uploaded_files/blog/original/".$menu['blog_banner'];
}

?>

<?php include('header.php');?>

    <!-- Full Screen Search Start -->
    <div class="modal fade" id="searchModal" tabindex="-1">
        <div class="modal-dialog modal-fullscreen">
            <div class="modal-content" style="background: rgba(9, 30, 62, .7);">
                <div class="modal-header border-0">
                    <button type="button" class="btn bg-white btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body d-flex align-items-center justify-content-center">
                    <div class="input-group" style="max-width: 600px;">
                        <input type="text" class="form-control bg-transparent border-primary p-3" placeholder="Type search keyword">
                        <button class="btn btn-primary px-4"><i class="bi bi-search"></i></button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Full Screen Search End -->


    <!-- Hero Start -->
    <div class="container-fluid bg-primary py-5 hero-headerblog-inner mb-5">
        <div class="row py-3">
            <div class="col-12 text-center">
                <h1 class="display-3 text-white animated zoomIn">Blog Details</h1>
                <a href="" class="h4 text-white">Home</a>
                <i class="far fa-circle text-white px-2"></i>
                <a href="" class="h4 text-white">Blog Details</a>
            </div>
        </div>
    </div>
    <!-- Hero End -->

		<!-- Single News -->
		<section class="news-single section">
			<div class="container">
				<div class="row">
					<div class="col-lg-8 col-12">
						<div class="row">
							<div class="col-12">
								<div class="single-main">
									<!-- News Head -->
									<div class="news-head">
										<img src="<?php echo SITE_WS_PATH."/uploaded_files/blog/original/".$menu['blog_banner'];?>" alt="#">
									</div>
									<!-- News Title -->
									<h1 class="news-title"><a href="#"><?php echo $menu['heading']; ?></a></h1>
									<!-- Meta -->
								
									<!-- News Text -->
									<div class="news-text">
								
								<?php echo stripcslashes($menu['content']); ?>
								</div>
							
								</div>
							</div>
				
						
						</div>
					</div>
					<div class="col-lg-4 col-12">
						<div class="main-sidebar">
							<!-- Single Widget -->
							<div class="single-widget search">
								<div class="form">
									<input type="email" placeholder="Search Here...">
									<a class="button" href="#"><i class="fa fa-search"></i></a>
								</div>
							</div>
							<!--/ End Single Widget -->
							<!-- Single Widget -->
							<div class="single-widget category">
								<h3 class="title">Blog Categories</h3>
								<ul class="categor-list">
								<!--	<li><a href="#">Men's Apparel</a></li>
									<li><a href="#">Women's Apparel</a></li>
									<li><a href="#">Bags Collection</a></li>
									<li><a href="#">Accessories</a></li>
									<li><a href="#">Sun Glasses</a></li>-->
									<?php 
// Query to get categories with blog counts
$blogCountlist = db_query("
  SELECT tbl_blogcatp.catP_Name AS category_name, COUNT(tbl_blog.cat_name) AS countnum
  FROM tbl_blogcatp
  LEFT JOIN tbl_blog ON tbl_blog.cat_name LIKE CONCAT('%', tbl_blogcatp.catP_Name, '%')
  WHERE tbl_blogcatp.status = 1
  GROUP BY tbl_blogcatp.catP_Name
");

while($blogWslist = mysqli_fetch_array($blogCountlist)){
    $catName = $blogWslist['category_name'];
    $countNum = $blogWslist['countnum'];
    
    // Display each category with its blog count
    if($countNum > 0) { // Only show categories with blogs
?>
   <li><a href="<?php echo SITE_WS_PATH.'/blog/'.str_replace(" ","-",strtolower($catName)); ?>" target="_blank" class="" style="">
      <i class="fa fa-arrow-circle-right" aria-hidden="true"></i>  <?php echo $catName; ?> (<?php echo $countNum; ?>)
    </a></li> 
<?php
    }
}
?>
								</ul>
							</div>
							<!--/ End Single Widget -->
							<!-- Single Widget -->
							<div class="single-widget recent-post">
								<h3 class="title">Recent post</h3>
								<!-- Single Post -->
									<?php
								$sqlmenu = db_query("SELECT * FROM tbl_blog WHERE heading!='".trim($menuurl)."' AND status=1 order by id DESC limit 0,4 ");
                               while( $menuPost = mysqli_fetch_array($sqlmenu)){ ?>
								<div class="single-post">
									<div class="image">
										<img src="<?php echo SITE_WS_PATH;?>/uploaded_files/blog/thumb/<?php echo $menuPost['blog_banner']; ?>" alt="#">
									</div>
									<div class="content">
									     <?php   $cleaned_heading = preg_replace('/[^a-zA-Z0-9\s]+/', '', $menuPost['heading']);
                                          $serviceUri = strtolower(str_replace(' ', '-', $cleaned_heading));?>
										<h5><a href="<?php echo SITE_WS_PATH;?>/blog/<?php echo $serviceUri;?>"><?php echo $menuPost['heading']?></a></h5>
									<!--	<ul class="comment">
											<li><i class="fa fa-calendar" aria-hidden="true"></i>Jan 11, 2020</li>
											<li><i class="fa fa-commenting-o" aria-hidden="true"></i>35</li>
										</ul>-->
									</div>
								</div>
								<?php } ?>
						
							</div>
							<!--/ End Single Widget -->
							<!-- Single Widget -->
							<!--/ End Single Widget -->
							<!-- Single Widget -->
							<div class="single-widget side-tags">
								<h3 class="title">Tags</h3>
								<ul class="tag">
							     <?php if($menu['tag1']!=''){ ?>	<li>   <a href="<?php echo SITE_WS_PATH.'/blog/tags/'.strtolower(str_replace(" ","-",trim($menu['tag1']))); ?>"><?php echo $menu['tag1']; ?></a></li><?php } ?>
								 <?php if($menu['tag2']!=''){ ?>	<li>   <a href="<?php echo SITE_WS_PATH.'/blog/tags/'.strtolower(str_replace(" ","-",trim($menu['tag2']))); ?>" class=""><?php echo $menu['tag2']; ?></a></li><?php } ?>
								 <?php if($menu['tag3']!=''){ ?>	<li>   <a href="<?php echo SITE_WS_PATH.'/blog/tags/'.strtolower(str_replace(" ","-",trim($menu['tag3']))); ?>" class=""><?php echo $menu['tag3']; ?></a></li><?php } ?>
								 <?php if($menu['tag4']!=''){ ?>	<li>  <a href="<?php echo SITE_WS_PATH.'/blog/tags/'.strtolower(str_replace(" ","-",trim($menu['tag4']))); ?>" class=""><?php echo $menu['tag4']; ?></a></li><?php } ?>
								 <?php if($menu['tag5']!=''){ ?>	<li>  <a href="<?php echo SITE_WS_PATH.'/blog/tags/'.strtolower(str_replace(" ","-",trim($menu['tag5']))); ?>" class=""><?php echo $menu['tag5']; ?></a></li><?php } ?>
								
								</ul>
							</div>
							<!--/ End Single Widget -->
						</div>
					</div>
				</div>
			</div>
		</section>
		<!--/ End Single News -->
		<?php include('footer.php');?>