<?php
$tt_page_info = array(
  'Page_Info' =>   array(
    'Title' => $the_category['CategoryName'],
    'Description' => trim(strip_tags($the_category['CategoryDescription'])),
    'Keyword' => '',
  ),
  'Social_og' => array(
    'Image' => '',
    'Type' => 'website',
    'URL' => str_replace($site_domain, '', categoryInfo( $the_category['CategoryID'] , 'url')),
  ),
);

require_once('./header.php'); // Include Footer
?>
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [{
      "@type": "ListItem",
      "position": 1,
      "item": {
        "@id": "<?php echo $site_domain ?>",
        "name": "Home"
      }
    },
    {
      "@type": "ListItem",
      "position": 2,
      "item": {
        "@id": "<?php echo categoryInfo( $the_category['CategoryID'] , 'url') ?>",
        "name": "<?php echo $the_category['CategoryName'] ?>"
      }

    }
  ]
}
</script>
<section class="py-4">
  <div class="container">
    <?php
    $category_ads_1 = showAds($advancenews['CategoryAds1'], $advancenews['CategoryAdsCtl']);
    if ($category_ads_1 != '') {
      ?>
      <div class="  mb-3">
        <?php echo $category_ads_1 ?>
      </div>
      <?php
    }
    ?>
    <div>
      <a href="<?php echo categoryInfo( $the_category['CategoryID'] , 'url') ?>">
        <h4 class="m-0 p_post_cat3"><?php echo $the_category['CategoryName'] ?></h4>
      </a>
      <?php
      $tp_cat_parent = $the_category['CategoryID'];
      $data_p_cat = showAllttdata("mahamudfutureit_category" , "WHERE   CategoryParent = '$tp_cat_parent' AND CategorySataus = 'Published'  ORDER BY  CategoryID  DESC ");
      if (!empty($data_p_cat)) {
        ?>
        <div class="mt-3">
          <?php
          foreach ($data_p_cat as $post_ccat) {
            ?>
            <a class="p_post_cat_sub2  " href="<?php echo categoryInfo( $post_ccat['CategoryID'] , 'url') ?>">
              <i class="bi bi-circle-fill cat_sub_icon"></i>
              <?php echo $post_ccat['CategoryName'] ?>
            </a>
            <?php
          }
           ?>
        </div>
        <?php
      }
      ?>
    </div>

    <?php
    $category_ads_2 = showAds($advancenews['CategoryAds2'], $advancenews['CategoryAdsCtl']);
    if ($category_ads_2 != '') {
      ?>
      <div class="  my-3">
        <?php echo $category_ads_2 ?>
      </div>
      <?php
    }
    ?>

    <?php
     $category_for_this_post = $the_category['CategoryID'];
     $the_item_post =  getArticles($category_for_this_post, 9);

     if (!empty($the_item_post)) {
       $count_the_item_post = 1;
       echo '<div class="row mt-3 g-3" id="news-container">';
       foreach ($the_item_post as $the_it_post) {
         if ($count_the_item_post == 1) {
           ?>
             <div class="col-md-9">
               <div class="">
                 <a href="<?php echo articleLink($the_it_post['PostId']) ?>"  class="d-block  prothom-songbad-post-style ">
                   <div class="row g-2  align-items-center">
                     <div class="col-md-5 order-2 order-md-1 col-12 mt-0 p-3 ">
                       <h1 class="news-title m-0 tt-text"><?php echo $the_it_post['PostTitle'] ?></h1>
                       <p class="summery-5">
                         <?php echo  strip_tags($the_it_post['PostContent']) ?>
                       </p>
                     </div>
                     <div class="col-md-7 order-1 order-md-2 col-12 mt-0 ">
                       <div class="position-relative overflow-hidden rounded-2">
                         <img class="w-100 ps-post-line-img"  src="<?php echo $advancenews['ArticlePreloader'] ?>"  data-src="<?php echo articleImg($the_it_post['PostId']) ?>" alt="<?php echo $the_it_post['PostTitle'] ?>">
                       </div>
                     </div>
                   </div>
                 </a>
               </div>
             </div>
             <div class="col-md-3">
               <?php
               $category_ads_3 = showAds($advancenews['CategoryAds3'], $advancenews['CategoryAdsCtl']);
               if ($category_ads_3 != '') {
                 ?>
                 <div class=" ">
                   <?php echo $category_ads_3 ?>
                 </div>
                 <?php
               }
               ?>
             </div>
           <?php
         }else {
           ?>
           <div class="col-md-3 col-6">
             <a href="<?php echo articleLink($the_it_post['PostId']) ?>"  class="d-block prothom-songbad-post-style">
               <div class="align-items-center">
                   <div class="position-relative overflow-hidden rounded-2">
                     <img class="w-100 ps-post-line-img"  src="<?php echo $advancenews['ArticlePreloader'] ?>"  data-src="<?php echo articleImg($the_it_post['PostId']) ?>" alt="<?php echo $the_it_post['PostTitle'] ?>">
                   </div>
                   <div class="p-2">
                     <h1 class=" news-title-2 m-0 tt-text"><?php echo $the_it_post['PostTitle'] ?></h1>
                   </div>
               </div>
             </a>
           </div>
           <?php
         }
         $count_the_item_post++;
       }
       echo '</div>';
       ?>
      <div class="row mb-2">
           <div id="loader" class="col-md-12 text-center py-3" style="display: none;"><img src="<?php echo $site_domain ?>assets/image/loading-post.gif" style=" height:40px;"></div>
           <div class="col-12 text-center py-3">
               <button class="btn btn-more-details tt-white tt-text" id="load-more-button"> আরো পড়ুন  </button>
           </div>
      </div>
       <?php
     }else {
       ?>
       <div class="row mb-3">
         <div class="col-12">
           <?php echo  noPost(); ?>
         </div>
       </div>
       <?php
     }
   ?>
   <?php
   $category_ads_8 = showAds($advancenews['CategoryAds8'], $advancenews['CategoryAdsCtl']);
   if ($category_ads_8 != '') {
     ?>
     <div class=" ">
       <?php echo $category_ads_8 ?>
     </div>
     <?php
   }
   ?>

  </div>
</section>
<script>
let page=3;
var data_type="ttcp";
data_id=<?php echo $the_category['CategoryID'] ?>;
let isLoading=!1;

function loadMoreNews() {
    if (isLoading) {
        return;
    }

    isLoading = true;
    $('#loader').show();

    $.ajax({
        url: '<?php echo $site_domain ?>ajax_master/load-post/',
        type: 'POST',
        data: {
            page: page ,
            data_id : data_id,
            data_type :data_type,

            },
        success: function(data) {
            const newsContainer = $('#news-container');
            newsContainer.append(data);

            page++;
            isLoading = false;
            $('#loader').hide();
            lazyLoadImages();
        },
        error: function(error) {
            isLoading = false;
            $('#loader').hide();
        }
    });
}
$('#load-more-button').click(function() {
    loadMoreNews();
});

</script>
<?php
require_once('./footer.php'); // Include Footer
?>
