<?php session_start();
   require_once("./config/config.php");
   $getcate = $_GET['cat'];
   if( $getcate !=""){
      $sql_blog_id = "SELECT * FROM blog_category_add WHERE category='$getcate' ORDER BY datecreated DESC";
      $myquery_blog_id=$conn->query($sql_blog_id);
      $mydara_blog_id =$myquery_blog_id->fetchAll();
      $row_found_blog_id = $myquery_blog_id->rowCount();

      
   $sql_blog = "SELECT * FROM blog_category_add WHERE category='$getcate' ORDER BY datecreated DESC";
   $myquery_blog=$conn->query($sql_blog);
   $mydara_blog =$myquery_blog->fetchAll();
   $row_found_blog = $myquery_blog->rowCount();
   $no_of_records_per_page = 12;
   if (isset($_GET['page']) && is_numeric($_GET['page'])) {
       $page = intval($_GET['page']);
   } else {
       $page = 1;
   }
   $abc = $_GET['page'];
   echo $abc;
   $start_from = ($page - 1) * $no_of_records_per_page;
   $total_pages_sql = "SELECT COUNT(*) FROM blog_category_add WHERE category='$getcate'";
   $result = $conn->query($total_pages_sql);
  
   $total_rows = $result->fetchAll();
   $row_found = $result->rowCount();
   
   $total_pages = ceil($row_found_blog / $no_of_records_per_page);
   //echo $total_pages;
   }else{
   $sql_blog_id = "SELECT * FROM blog_category_add ORDER BY datecreated DESC";
   $myquery_blog_id=$conn->query($sql_blog_id);
   $mydara_blog_id =$myquery_blog_id->fetchAll();
   $row_found_blog_id = $myquery_blog_id->rowCount();

   $sql_blog = "SELECT * FROM blog_category_add";
   $myquery_blog=$conn->query($sql_blog);
   $mydara_blog =$myquery_blog->fetchAll();
   $row_found_blog = $myquery_blog->rowCount();
   $no_of_records_per_page = 12;
   if (isset($_GET['page']) && is_numeric($_GET['page'])) {
       $page = intval($_GET['page']);
   } else {
       $page = 1;
   }
   
   $start_from = ($page - 1) * $no_of_records_per_page;
   $total_pages_sql = "SELECT COUNT(*) FROM blog_category_add";
   $result = $conn->query($total_pages_sql);
  
   $total_rows = $result->fetchAll();
   $row_found = $result->rowCount();
   //  var_dump($row_found_blog_id);
   //  die;
   $total_pages = ceil($row_found_blog / $no_of_records_per_page);
   }
   

   if( $getcate !=""){
   $stmt = $conn->prepare("SELECT * FROM blog_category_add  WHERE category='$getcate' ORDER BY datecreated DESC LIMIT $start_from, $no_of_records_per_page");
   }else{
      $stmt = $conn->prepare("SELECT * FROM blog_category_add ORDER BY datecreated DESC LIMIT $start_from, $no_of_records_per_page");
   }
  // var_dump($stmt);
   $stmt->execute();
   $users = $stmt->fetchAll();

   
      // This is a code for php minifiers Begin
      ob_start("minifier");
      function minifier($code) {
          $search = array(
               
              // Remove whitespaces after tags
              '/\>[^\S ]+/s',
               
              // Remove whitespaces before tags
              '/[^\S ]+\</s',
               
              // Remove multiple whitespace sequences
              '/(\s)+/s',
               
              // Removes comments
              '/<!--(.|\s)*?-->/'
          );
          $replace = array('>', '<', '\\1');
          $code = preg_replace($search, $replace, $code);
          return $code;
      }
      // This is a code for php minifiers End

   ?>
<!DOCTYPE html>
<html lang="en">
   <head>
      <!-- Character set configuration -->
      <base href="<?=$base_link?>" target="_self">
      <meta charset="UTF-8" />
      <title>icouponworld- Online Shopping Tips, Buying Guide, Savings</title>
      <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <link id="favicon" rel="icon" type="image/x-icon" href="images/web-images/home/favicon.png"/>
      <meta name="robots" content="index, follow" />
      <meta name="description" content="Promo Code: Latest &amp; Valid Paytm Coupons and Promo codes when you shop online. Avail discounts, cashbacks and vouchers across">
      <meta name="keywords" content="Best Coupons, Promo Codes, coupon code offers, Coupon Code, Promotion Codes, Discount Deals">
      <link rel="canonical" href="blog.php"/>
      <!-- Viewport configuration, scaling options -->
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>

      <!-- CSS Stylesheet -->
      <link href="css/icouponworld.css" rel="stylesheet" />
      <!-- Font Awesome icon -->
      <link href="fontawesome/css/fontawesome.css" rel="stylesheet" />
      <!-- Owl Stylesheets -->
      <!-- <link rel="stylesheet" href="css/owl.carousel.min.css">
      <link rel="stylesheet" href="css/owl.theme.default.min.css"> -->
      <!-- Google Analytics Code Begin-->
      <?=$google_ana ?>
      <!-- Google Analytics Code End-->
      <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
      <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
      <![endif]-->
   </head>
   <body>
      <!-- Preloader Begin-->
      <div class="preloader">
         <div class="loading">
            <img src="images/web-images/home/loader.gif" alt="loader" title="loader" class="mx-auto d-flex"> 
            <h2 class="text-center fw-light">loading...</h2>
         </div>
      </div>
      <!-- Preloader End-->
      <!--Header Begin-->
      <?php include("./includefiles/header.php");   ?> 
      <!--Header End-->
      <!--Overlay Begin-->
      <div id="overlay"></div>
      <!--Overlay End-->
      <!--Posts Begin-->
      <section class="bg-white gap-top">
         <div class="container">
            <div class="row">
               <div class="col-md-9">
                  <h1 class="h5 pt-5 pb-4">Latest Posts</h1>
                  <!--latest-post-left-->
                  <?php
                              if($row_found_blog_id>0){
                                 foreach( $users as $row_form){
                                   $metatitles = $row_form['metatitle'];
                                   $metadesc = $row_form['metadesc'];
                                    $metakey = $row_form['metakey'];     
                                    $images = $row_form['blog_image']; 
                                    $editor = $row_form['editor1']; 
                                    $blog_title = $row_form['blogtitle']; 
                                    $dates = strtotime($row_form['datecreated']); 
                                    $categorys = $row_form['category'];
                                    $ids = $row_form['idcodes'];
                                    $addblog = $row_form['addblog'];
                           ?>
                  <div class="latest-post-left">
                     <div class="d-lg-flex">
                        <div class="flex-shrink-0">
                           <a href="blog-detail/<?=$addblog?>"><img src="./admin/backend/<?=$images?>" width="170" class="img-fluid rounded-3" alt="..."></a>
                        </div>
                        <div class="flex-grow-1 ms-lg-3">
                           <a href="blog-detail/<?=$addblog?>" class="d-grid text-decoration-none">
                              <h5 class="mb-2"><?=$blog_title?></h5>
                           </a>
                           <div class="d-grid">
                              <p class="text-truncate"><?=$metadesc?></p>
                           </div>
                           <div class="post-admin">
                              <span> <img alt="user" tittle="user" src="./admin/backend/<?=$profile_pic?>"  class="img-fluid rounded-circle" width="22"> <?=$full_name?> </span> 
                              <span> <?php echo date("M d, y", $dates);?> </span>
                           </div>
                        </div>
                     </div>
                  </div>
                  <?php  }   }  ?>
                  <!--pagination Begin-->
                  <?php if( $getcate ==""){?>
                  <nav>
               <ul class="pagination justify-content-center">
                  <li class="page-item <?php if($page <= 1){ echo 'disabled'; } ?>">
                     <a class="page-link" href="blogs-pg/<?php echo $page - 1; ?>">Previous</a>
                  </li>
                  <?php for($i=1; $i<=$total_pages; $i++): ?>
                  <li class="page-item <?php if($page == $i){ echo 'active'; } ?>">
                     <a class="page-link" href="blogs-pg/<?php echo $i; ?>"><?php echo $i; ?></a>
                  </li>
                  <?php endfor; ?>
                  <li class="page-item <?php if($page >= $total_pages){ echo 'disabled'; } ?>">
                     <a class="page-link" href="blogs-pg/<?php echo $page + 1; ?>">Next</a>
                  </li>
               </ul>
            </nav>
            <?php }  ?>
            <?php if( $getcate !=""){?>
                  <nav>
               <ul class="pagination justify-content-center">
                  <li class="page-item <?php if($page <= 1){ echo 'disabled'; } ?>">
                     <a class="page-link" href="blogs-section/<?=$getcate?>/<?php echo $page - 1; ?>">Previous</a>
                  </li>
                  <?php for($i=1; $i<=$total_pages; $i++): ?>
                  <li class="page-item <?php if($page == $i){ echo 'active'; } ?>">
                     <a class="page-link" href="blogs-section/<?=$getcate?>/<?php echo $i; ?>"><?php echo $i; ?></a>
                  </li>
                  <?php endfor; ?>
                  <li class="page-item <?php if($page >= $total_pages){ echo 'disabled'; } ?>">
                     <a class="page-link" href="blogs-section/<?=$getcate?>/<?php echo $page + 1; ?>">Next</a>
                  </li>
               </ul>
            </nav>
           
            <?php }  ?>
                  <!--Pagination End-->

                  <div class="py-5">
                       <!--Banner Begin-->
            <?php    if(!empty($google_adar )){
               echo $google_adar ;
               }else{
               echo ' <img src="admin/forms/'.$adimg3.'" alt="Horizontal Banner" title="Horizontal Banner" class="img-fluid w-100 rounded-3 py-5">';
               } ?>
            <!--Banner End-->
                  </div>
                  
               </div>
               <div class="col-md-3">
                  <div class="search pt-5 pb-4">
                     <!-- <div class="title">
                        Search
                     </div>
                     <div class="input-group mb-3">
                        <input type="text" class="form-control" placeholder="" aria-label="Recipient's username">
                        <span class="input-group-text bg-primary cursor-pointer"><i class="text-white fas fa-search"></i></span>
                     </div> -->
                     <div class="title pt-4">
                        lattest Post
                     </div>
                     <!--lattest-post-right-->
                     <?php
                          $sql_category_way = "SELECT category, COUNT(*) FROM `blog_category_add` GROUP BY category limit 7";
                          $myquery_category_way=$conn->query($sql_category_way);
                          $mydara_category_way =$myquery_category_way->fetchAll();
                          $row_found_category_way = $myquery_category_way->rowCount();
                        // var_dump($mydara_category_way);
                        if( $row_found_category_way>0){
                           foreach($mydara_category_way as $row_form){
                               
                             
                              $categorys1 = $row_form['category'];
                             $count =  $row_form['COUNT(*)'];
                            //echo  $count;
                     ?>
                     <div class="lattest-post-right">
                        <div class="d-flex">
                           <div class="flex-shrink-0">
                              <?php
                                $sql_categorys = "SELECT * FROM blog_category_add  WHERE category = '$categorys1' ORDER BY datecreated DESC  limit 1";
                                $myquery_categorys=$conn->query($sql_categorys);
                                $mydara_categorys =$myquery_categorys->fetchAll();
                                $row_found_categorys = $myquery_categorys->rowCount();
                              // var_dump($mydara_category_way);
                              if( $row_found_categorys>0){
                                 foreach($mydara_categorys as $row_form){
                                     
                                   
                                    $blog_pic = $row_form['blog_image'];
                                    $blog_title1 = $row_form['blogtitle'];
                                   
                           ?>
                              <a href="blog-category/<?=$categorys1?>"><img src="./admin/backend/<?=$blog_pic?>" class="img-fluid rounded-3" alt="img" width="130"></a>
                           </div>
                           <div class="flex-grow-1 ms-3 mt-2">
                              <a href="blog-category/<?=$categorys1?>" class="d-grid text-decoration-none">
                                 <h6 class="fs-12 fw-bold text-truncate"><?=$blog_title1?></h6>
                                 <p class="fst-italic fs-12 text-truncate pt-1"><?=$categorys1?> </p>
                                 <div>
                                    <?php } } ?>
                                    
                                    <span class="badge bg-primary rounded-pill"><?php echo $count;?></span>
                                   
                                 </div>
                              </a>
                           </div>
                        </div>
                     </div>
                     <?php }  }  ?>
                     <!--Top Stores-->
                     <!--Coupons from Similar Stores Begin-->
   <div class="similar-store">
      <div class="my-4"></div>
      <h6 class="mb-3">popular Brand</h6>
      <ul class="list-unstyled">
         <?php  $sqlcategory="SELECT * FROM  brand_master ORDER BY rand() LIMIT 6";
            $myquerycou=$conn->query($sqlcategory);
            $mydaracategory= $myquerycou->fetchAll()  ;
            
            $rows_foundcou = $myquerycou->rowCount();
            
            foreach( $mydaracategory as $rowcat ){  
            
            $brand_name = addslashes($rowcat["brand_name"]); 
            if($brand_name!=''){
            ?>
         <li><a title="<?=$brand_name?>" href="brand-specific/<?=($brand_name)?>"> <?=$brand_name?></a></li>
         <?php } } ?>
      </ul>
   </div>
   <!--Coupons from Similar Stores End-->
   <!--Popular Stores Begin-->
   <div class="similar-store">
      <div class="divider my-3"></div>
      <h6 class="mb-3">Popular Stores</h6>
      <ul class="list-unstyled">
         <?php  $sqlcategory="SELECT * FROM  store_master ORDER BY rand() LIMIT 6";
            $myquerycou=$conn->query($sqlcategory);
            $mydaracategory= $myquerycou->fetchAll()  ;
            
            $rows_foundcou = $myquerycou->rowCount();
            
            foreach( $mydaracategory as $rowcat ){  
            
            $store_name = addslashes($rowcat["store_name"]); 
            if($store_name!=''){
            ?>
         <li><a title="<?=$store_name?>" href="store-specific/<?=($store_name)?>"><?=$store_name?></a></li>
         <?php } } ?>
      </ul>
   </div>
   <!--Popular Stores End-->
   <div class="mb-3">
    <?php    if(!empty($google_adar )){
      echo $google_adar ;
      }else{
      echo ' <img src="admin/forms/'.$adimg1.'" alt="Vertical Banner" title="Vertical Banner" class="img-fluid rounded-3 mt-2">';
      }
      
      ?>
</div>
   <!--Banner End-->
       <!--Google Ads Begin-->
       <div class="mb-3"><?=$google_addis?></div>
                  </div>
               </div>
            </div>
         </div>
      </section>
      <!--Posts End-->
      <!--footer Section Begin-->
      <?php include("./includefiles/footer.php");   ?>
      <!--footer Section End-->
      <!--scroll to top Begin-->
      <button onclick="topFunction()" id="gobackToTop" title="Go To Top"><i class="fas fa-angle-up"></i></button>
      <!--scroll to top end-->
      <!-- jquery-3.4.1.min js Begin-->
      <script src="js/jquery-3.4.1.min.js"></script>
      <!-- jquery-3.4.1.min js End-->
      <!-- bootstrap.bundle.min js Begin-->
      <script src="js/bootstrap.bundle.min.js"></script>
      <!-- bootstrap.bundle.min js End-->
      <!-- icouponworld js Begin-->
      <script src="js/icouponworld.js"></script>
      <!-- icouponworld js End-->
      <!--script for googleTranslateElementInit Begin-->
      <!-- <script>
         function googleTranslateElementInit() {
  new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
      </script> -->
      <!--script for googleTranslateElementInit End-->
      <!--script for googleTranslate Begin-->
      <!-- <script src="js/googletranslate.js"></script> -->
      <!--script for googleTranslate End-->
   </body>
</html>
<?php
ob_end_flush();  // This is a code for php minifiers
?>