

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

    .dropbtn {
  background-color:#1c3470 !important;
  color: white;
  padding: 7px;
  font-size: 20px;
  font-weight:bold;
  border-radius:5px;
  border: none;
  cursor: pointer;
  width:100%;
}

.dropbtn:hover, .dropbtn:focus {
  background-color: #083d51;
}

.dropdown2 {
  position: relative;
  display: inline-block;
  width:50%;
  float:right;
}

.dropdown-content2 {
    width:100%;
  display: none;
  position: absolute;
  background-color: #fff;
  min-width: 160px;
  overflow: auto;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
  font-size:18px;
}

.dropdown-content2 a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.dropdown2 a:hover {background-color: #ddd;}

.show {display: block;}
@media (max-width: 799px){
    .dropdown2{
        float: left;
    margin-bottom: 10px;
    margin-top: -20px;
    }
}
</style>
<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://metalstamping-dies.com/about-us')
{
?><img src="<?php echo SITE_WS_PATH; ?>/images/slider/About-us.webp" alt="about us"/>"<?php
}
elseif($urls=='https://www.metalstamping-dies.com/knowledge-base')
{
?> <img src="<?php echo SITE_WS_PATH; ?>/images/slider/Blog.webp" alt="Blog"/>"<?php    
}
elseif($urls=='https://metalstamping-dies.com/tooling')
{
?> <img src="<?php echo SITE_WS_PATH; ?>/images/slider/Tooling.webp" alt="Tooling"/>"<?php    
}
elseif($urls=='https://metalstamping-dies.com/stamping')
{
?> <img src="<?php echo SITE_WS_PATH; ?>/images/slider/Stamping.webp" alt="Stamping"/>"<?php    
}
elseif($urls=='https://metalstamping-dies.com/die-designing')
{
?> <img src="<?php echo SITE_WS_PATH; ?>/images/slider/Die-Designing.webp" alt="Die Designing"/>"<?php    
}
elseif($urls=='https://metalstamping-dies.com/contact-us')
{
?> <img src="<?php echo SITE_WS_PATH; ?>/images/slider/Contact-Us.webp" alt="Contact Us"/>"<?php    
}
?>
</ul>
</div>
<?php
//------------ start of knowledge base------------------
if($blogurl=='Knowledge Base'){?>
<div id="content">
<br />

<div class="container">
    	<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>
 
</ol>
    <div class="col-md-12" style="margin-bottom:20px;" >
        <div class="col-md-6"><p class="rblo" style="font-weight:bold;font-size:22px">OUR RECENT BLOGS</p></div>
    <div class="col-md-6">
        <p>
        <div class="dropdown2">
  <button onclick="myFunction()" class="dropbtn">Blog Categories</button>
  <div id="myDropdown" class="dropdown-content2">
  <?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">
        <?php echo $catName; ?> (<?php echo $countNum; ?>)
    </a>
<?php
    }
}
?>

  </div>
</div>
</p>
    </div>
</div>
</div>
<div class="container">

<div class="col-md-12" >

<!--<ol class="breadcrumb y">
<p class="rblo">OUR RECENT BLOGS</p>
<? 
/*$blogCount=db_query("SELECT catP_Name from tbl_blogcatp where status=1");
while($blogWs=mysqli_fetch_array($blogCount)){
	$blogCountA=db_query("SELECT cat_name from tbl_blog where cat_name LIKE '%$blogWs[catP_Name]%'");
    $count=0;
    while($blogW=mysqli_fetch_array($blogCountA)){
		$count++;
    } ?>
<li><a href="<?php echo SITE_WS_PATH.'/knowledge-base/'.''.str_replace(" ","-",strtolower($blogWs['catP_Name']));?>" class="btn btn-primary hu"><?php echo $blogWs['catP_Name']; ?> ( <?php echo $count; ?> )</a></li>
   <?php } */?>
</ol>-->

<?php
$req = $_SERVER['HTTP_HOST'].''.$_SERVER['REQUEST_URI'];
$exsp = explode("/", $req);
$start =$exsp[1];
$dsdsd = explode("/", $req);
$poison=$dsdsd[2] ?? '';
$poisonA=explode("?", $poison);
$poisonB=ucwords(str_replace("-"," ",$poisonA[0]));
$start = intval($start);
$pagesize=0;
$order_by=0;
$order_by2=0;
$pagesize = intval($pagesize)==0?$pagesize=55:$pagesize;
//print_r($pagesize); exit;
$columns = "select * ";
$sql = " from `tbl_blog` ";
$sql .= " where status= '1' order by id DESC ";
if($poisonB !=""){
  $sql .= "and cat_name LIKE '%$poisonB%'";
}
//$order_by == '' ? $order_by = ' `id`' : true;
//$order_by2 == '' ? $order_by2 = 'ASC' : true;
$sql_count = "select count(*) ".$sql; 
//$sql .= "order by $order_by $order_by2 ";
//$sql .= "order by $order_by $order_by2 ";
//$sql .= "limit $start, $pagesize ";
$sql = $columns.$sql;
//print_r($sql);exit();
$result = db_query($sql);
?>
<?php
if($start==0){
  $cnt=0;
}
else{
  $cnt=$start;
}
while($line_raw = mysqli_fetch_array($result)) {
  $cnt++;
@extract($line_raw);

?>
<div class="col-md-6"> 
  <div class="well bn">
      <div class="media">
      	<a class="pull-left" href="<?php echo SITE_WS_PATH.'/knowledge-base/'.$serviceUri=str_replace(" ", "-",strtolower($heading)); ?>">
    		<img class="media-object" src="<?php echo SITE_WS_PATH."/uploaded_files/blog/original/".$blog_banner; ?>" alt=<?php echo $alt; ?>>
  		</a>
  	<div class="media-body">
  	 <ul class="list-inline list-unstyled">
  	 <!--<p class="text-right"><?php //echo $post_writer; ?></p>-->
  	
  			
           <?php $fetchSQL = mysqli_fetch_array(db_query("SELECT cat_name from tbl_blog where id='$id' "));
	 $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
	}
	?>
		 
	</ul>
	<h1 class="media-heading hjk"><a style="text-decoration:none;" href="<?php echo SITE_WS_PATH.'/knowledge-base/'.$serviceUri=str_replace(" ", "-",strtolower($heading)); ?>"> <?php echo substr(strip_tags(ucwords($heading)), 0, 38).'...'?></a></h1>
          
          <p><?php echo substr(strip_tags(($line_raw['content'])), 0, 100).'...'; ?></p>
          <p class="readmm"><a href="<?php echo SITE_WS_PATH.'/knowledge-base/'.$serviceUri=str_replace(" ", "-",strtolower($heading));  ?>">Read more <i class="fa fa-angle-right"></i></a></p>
	
	
    </div>
    </div>
  </div>
  </div>
<?php }?>
</div>
<!--<div class="col-lg-3 right-form">
<div class="list-group" style="border-radius: 4px;">
 <ol class="breadcrumb" style="    background: #8e8d8d; color: #fff;  font-size: x-large;">Latest Blog</ol>
  <?php $sql123 = db_query("select heading from tbl_blog where status=1 order by id DESC 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;"><i class="fa fa-link" aria-hidden="true"></i> <?php echo ucfirst(substr($ddd['heading'], 0, 30)).'...';?></a>  
   <?php } ?>
</div>
</div> -->

</div>
</div>
<?php }else{?>
<?php include('index_banner.php'); ?>
<div class="welcome-sec">
<div class="container cf">

<div class="welcome-img">
<?php include('right_menu.php'); ?>
</div>
<?php
$url = explode('/', rtrim($_SERVER["REQUEST_URI"],"/")); 
$count=count($url);
$menuurl = ucwords(str_replace('-', ' ',$url[$count-1]));
$sqlmenu=db_query("SELECT * FROM `the_menu`  where name='".trim($menuurl)."' and status=1");
$menu=mysqli_fetch_array($sqlmenu);
$menuother= $menu['name'] ?? '';
$menucontent= $menu['content'] ?? '';

?>

<p><?php echo $menucontent; ?></p>
</div>
</div>
<?php } ?>
</main>
</div>
</div>
<?php include('footer.php'); ?>