<?php require_once('includes/cmain.inc.php');?>
<?php 
$url = explode('/', rtrim($_SERVER["REQUEST_URI"],"/")); 
//print_r($url);exit();
$count=count($url);
$urltag=str_replace('-',' ',trim($url[3]));
$urls= SITE_WS_PATH.'/'.$url[1];
$menuurl = ucwords(str_replace('-', ' ',$url[$count-1]));
//print_r($menuurl);exit();
if($menuurl!='Tags'){
$search_terms = explode(" ", $menuurl);
$sql_parts = array();
foreach ($search_terms as $term) {
    $sql_parts[] = "heading LIKE '%$term%'";
}
$sql_condition = implode(" OR ", $sql_parts);
}
else{
    $sql_condition=1;
}
//print_r("SELECT * FROM `tbl_blog` where $sql_condition and status='1'");exit();
$sqlmenu=db_query("SELECT * FROM `tbl_blog` where $sql_condition and status='1'");
$result = $sqlmenu;


?>
<?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-header mb-5">
        <div class="row py-3">
            <div class="col-12 text-center">
                <h1 class="display-3 text-white animated zoomIn">Blog</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</a>
            </div>
        </div>
    </div>
    <!-- Hero End -->


        <!-- Blog Start -->
        <div class="container-fluid blog py-5">
            <div class="container py-5">
                
                <div class="row g-4 justify-content-center">
  <?php
while ($line_raw = mysqli_fetch_array($result)) {
 //print_r($line_raw);exit();

?>
              
                    <div class="col-lg-6 col-xl-4 wow fadeInUp" data-wow-delay="0.2s">
                        <div class="blog-item">
                            <div class="blog-img">
                                <img src="<?php echo SITE_WS_PATH."/uploaded_files/blog/original/".$line_raw['blog_banner'];?>" class="img-fluid rounded-top w-100" alt="">
                                <div class="blog-categiry py-2 px-4">
                                    <span> <?php $fetchSQL = mysqli_fetch_array(db_query("SELECT cat_name from tbl_blog where id='".$line_raw['id']."' "));
	 $items= explode(",", $fetchSQL['cat_name']); 
	foreach($items as $value){ 
	$dynamicURL= SITE_WS_PATH.'/blog/'.strtolower(str_replace(" ","-",$value));
    echo "<a href='$dynamicURL' class='btn btn-xs btn-primary'>".$value."</a>"; }  ?></span>
                                </div>
                            </div>
                            <div class="blog-content p-4">
                               
                                <a href="<?php echo SITE_WS_PATH.'/blog/'.$serviceUri=str_replace(" ", "-",strtolower($line_raw['heading'])); ?>" class="h4 d-inline-block mb-3"><?php echo $line_raw['heading'];?></a>
                                <p class="mb-3">
                                <?php $content = $line_raw['content'];

                                 $content = preg_replace('/<style\b[^>]*>(.*?)<\/style>/is', '', $content);
                                 $content = preg_replace('/<script\b[^>]*>(.*?)<\/script>/is', '', $content);
                                  $content = preg_replace('/<[^>]+>/', '', $content);
                                  echo substr(($content), 0, 100); ?></p>
                                <a href="<?php echo SITE_WS_PATH.'/blog/'.$serviceUri=str_replace(" ", "-",strtolower($line_raw['heading'])); ?>" class="btn p-0">Read More  <i class="fa fa-arrow-right"></i></a>
                            </div>
                        </div>
                    </div>
    <?php } ?>                
                
                </div>
            </div>
        </div>
        <!-- Blog End -->

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