<?// require('includes/cmain.inc.php'); ?>
<?php
$url = explode('/', rtrim($_SERVER["REQUEST_URI"],"/")); 
$count=count($url);
$urltag=str_replace('-',' ',trim($url[2]));
$urls= SITE_WS_PATH.'/'.$url[1];
$menuurl = ucwords(str_replace('-', ' ',$url[$count-1]));
$sqlmenu=db_query("SELECT * FROM `tbl_blog`  where heading='".trim($menuurl)."' and status=1");
$menu=mysqli_fetch_array($sqlmenu);
$titlekb =$menu['heading'] ?? '';
$descriptionkb=$menu['description'] ?? '';
$keywordkb=$menu['keyword'] ?? '';
$urlkb=$url[2] ?? '';
$meta_url=$a;
$meta_image=SITE_WS_PATH."/uploaded_files/blog/original/".($menu['blog_banner'] ?? '');

?>

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

<div class="home-banner">
<ul class="home_slider cf mhide">    
<?php
$url = explode('/', rtrim($_SERVER["REQUEST_URI"],"/"));
$urls= SITE_WS_PATH.'/'.$url[1];
//'<pre>'; print_r($urls) ; '<pre>';
$blogurl = ucwords(str_replace('-', ' ',$url[1]));
if($urls=='https://www.metalstamping-dies.com/knowledge-base')
{
?> <img src="<?php echo SITE_WS_PATH; ?>/images/slider/Blog.webp" alt="Blog"/><?php    
}
?>
</ul>
</div>
<!-------------- start of knowledge base------------------>
<div class="welcome-sec">
<div class="container cf">

<div id="content"><br />
<div class="container">
<div class="col-lg-9 col-md-9 col-sm-12" >
	<ol class="breadcrumb breadcrumb-arrow">
  <li><a href="<?php echo SITE_WS_PATH; ?>">Home</a></li>
  <li><a href="<?php echo SITE_WS_PATH.'/knowledge-base';?>"> Knowledge Base</a></li>
  <li class="active"><span><?php echo ucwords($urltag); ?></span></li>
</ol>


<?php  $requri = $_SERVER['HTTP_HOST'].''.$_SERVER['REQUEST_URI']; 
       $segment =explode("/",$requri);   
	   $segment3=$segment[2];
	   $countryName= ucwords(str_replace('-',' ',trim($segment3)));
       $sql = "select * from `tbl_blog` where heading = '$countryName'";
	    $result = db_query($sql);
	  
	    if ($line_raw = mysqli_fetch_array($result)) {
		@extract($line_raw);
	    }
?>

  <div class="well gh">
      <div class="media" style="height:auto;">
              		<ul class="list-inline list-unstyled" style="border:unset;">
              		    <?php $id= $id ?? ''; ?> 
  			<li><?php $fetchSQL = mysqli_fetch_array(db_query("SELECT cat_name from tbl_blog where id='".($id)."' and heading = '".$countryName."'"));
	 $items= explode(",", ($fetchSQL['cat_name'] ?? '')); 
	foreach($items as $value){ 
	$dynamicURL=SITE_WS_PATH.'/knowledge-base/'.strtolower(str_replace(" ","-",$value));
    echo "<a href='$dynamicURL' class='btn btn-xs btn-primary'>".$value."</a>";   ?>  
	<?php } ?></li>
			<!-- <p class="text-right vb"><span class="postb"> Posted by </span><? //echo $post_writer; ?></p>-->
            
			</ul>
      		<h1 class="media-heading innerh1"> <?php echo $countryName; ?></h1>
  
			
					 <ul class="aqkoj list-inline list-unstyled authrname" style="margin-left:10px;">
			 <p class="innertext-author"><span class="postb"></span> <?php //echo $post_writer; ?><img src="<?php  echo SITE_WS_PATH;?>/images/writer-icon3.png" class="writer-icon" width="20" height="20" />
			<!-- <a href="https://www.linkedin.com/in/raj-madan/" target="_blank" style="color:#f6821d;" >Rajesh Madan</a>-->
			 <a href="#" target="_blank" style="color:#f6821d;" >Admin</a>
			 <div class="blog-icons">
      <!--  <a href="https://www.facebook.com/sharer/sharer.php?u=<?// echo urlencode($post_url); ?>" target="_blank">
          <i class=""><img src="<?//  echo SITE_WS_PATH;?>/images/fb.png" height="25" width="25" ></i>
        </a>
        <a href="https://twitter.com/intent/tweet?text=<?//echo urlencode($post_title); ?>&url=<?// echo urlencode($post_url); ?>" target="_blank">
        <i class=""><img src="<?  //echo SITE_WS_PATH;?>/images/twitter.png" height="25" width="25" ></i>
        </a>
        <a href="https://www.linkedin.com/sharing/share-offsite/?url=<? //echo urlencode($post_url); ?>" target="_blank">
           <i class=""><img src="<? // echo SITE_WS_PATH;?>/images/ln.png" height="25" width="25" ></i>
        </a>
        <a href="https://pinterest.com/pin/create/button/?url=<?// echo urlencode($post_url); ?>&media=&description=<? //echo urlencode($post_title); ?>" target="_blank">
       <img src="<?//  echo SITE_WS_PATH;?>/images/pin.png" height="25" width="25" ></i>
    </a>
    <a href="https://www.instagram.com/?url=<?// echo urlencode($post_url); ?>" target="_blank">
       <i class=""><img src="<? // echo SITE_WS_PATH;?>/images/insta.png" height="25" width="25" ></i>
    </a>-->
    </div>
			 </p>
            
			</ul>
		<?php $sv_image = $blog_banner ?? '';
		  //if(($sv_image != "") && (file_exists(UP_FILES_WS_PATH."/blog/original/".$sv_image))){
	    if($sv_image != ""){
		    $imgsrc=SITE_WS_PATH."/uploaded_files/blog/original/".$sv_image;		
	//	$size=getimagesize(UP_FILES_WS_PATH."/blog/original/".$sv_image); ?>	
		<a>
		<?php 
		echo '<img src="'.$imgsrc.'" alt="'.$alt.'" style="width:100%; height:400px" />';
		} else  ?>
		</a>
		<?php {  echo ''; } ?>
		
  		<div class="media-body kl">         
          <p><?php echo stripcslashes($content ?? ''); ?></p>
           <?php  if(isset($conclusion)!=''){ ?>
          <p><?php echo stripcslashes($conclusion ?? ''); ?></p>
          <?php } ?>
          
       </div>
       <hr style="border-top:1px solid #8f7777;">
           <div class="tagclass">
        <div class="tagclass1">
     <?php   if(isset($tag1)!='' || isset($tag2)!='' || isset($tag3)!='' || isset($tag4)!='' || isset($tag5)!=''){?>
      <b class="">Tags</b>
       <?php }else{echo "";} ?>
       </div>
       <div class="tagclass2">
       <?php if(isset($tag1)!=''){ ?> <a href="<?php echo SITE_WS_PATH.'/knowledge-base/tags/'.strtolower(str_replace(" ","-",$tag1)); ?>" class="btn btn-primary hu btn-ch"><?php echo ucwords($tag1); ?></a><?php } ?>
        <?php if(isset($tag2)!=''){ ?><a href="<?php echo SITE_WS_PATH.'/knowledge-base/tags/'.strtolower(str_replace(" ","-",$tag2)); ?>" class="btn btn-primary hu btn-ch"><?php echo ucwords($tag2); ?></a><?php } ?>
         
       <?php if(isset($tag3)!=''){ ?> <a href="<?php echo SITE_WS_PATH.'/knowledge-base/tags/'.strtolower(str_replace(" ","-",$tag3)); ?>" class="btn btn-primary hu btn-ch"><?php echo ucwords($tag3); ?></a><?php } ?>
        <?php if(isset($tag4)!=''){ ?><a href="<?php echo SITE_WS_PATH.'/knowledge-base/tags/'.strtolower(str_replace(" ","-",$tag4)); ?>" class="btn btn-primary hu btn-ch"><?php echo ucwords($tag4); ?></a><?php } ?>
        <?php if(isset($tag5)!=''){ ?><a href="<?php echo SITE_WS_PATH.'/knowledge-base/tags/'.strtolower(str_replace(" ","-",$tag5)); ?>" class="btn btn-primary hu btn-ch"><?php echo ucwords($tag5); ?></a><?php } ?>

</div>
</div>
    </div>
  </div>
  
</div>

				
<div class="col-lg-3 right-form">
<div class="list-group" style="border-radius: 4px;margin-top:100px;">
 <ol class="breadcrumb" style="background: #1c3470  !important; color:white; font-size: x-large;">Blog Categories</ol>
 <?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
?>
    <a href="<?php echo SITE_WS_PATH.'/knowledge-base/'.str_replace(" ","-",strtolower($catName)); ?>" target="_blank" class="list-group-item" style="font-weight:bold !important;">
      <i class="fa fa-arrow-circle-right" aria-hidden="true"></i>  <?php echo $catName; ?> (<?php echo $countNum; ?>)
    </a>
<?php
    }
}
?>
</div>
<div class="list-group" style="border-radius: 4px;">
 <ol class="breadcrumb" style="    background: #1c3470 ; color: #fff;  font-size: x-large;">Latest Blog</ol>
  <?php $sql123 = db_query("select heading from tbl_blog where status=1 order by id ASC limit 10");
        while ($ddd = mysqli_fetch_array($sql123)) { ?>
        <a href="<?php echo SITE_WS_PATH.'/knowledge-base/'.$serviceUri=str_replace(" ", "-",strtolower($ddd['heading'])); ?>" class="list-group-item" style="line-height: 2em;font-weight:bold !important;"><i class="fa fa-link" aria-hidden="true"></i> <?php echo ucfirst(substr($ddd['heading'], 0, 30)).'...';?></a>  
   <?php } ?>
</div>
</div> 


</div>	
 </div>

</div>
</div>
</main>
</div>
</div>
<?php include('footer.php'); ?>