<?php
$tt_page_info = array(
  'Page_Info' =>   array(
    'Title' => $this_topic,
    'Description' => '',
    'Keyword' => '',
  ),
  'Social_og' => array(
    'Image' => '',
    'Type' => 'website',
    'URL' =>str_replace($site_domain, '', getTopicsUrl($this_topic)),
  ),
);

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 getTopicsUrl($this_topic) ?>",
        "name": "<?php echo $this_topic ?>"
      }

    }
  ]
}
</script>
<section class="py-4">
  <div class="container">
    <?php
    $category_ads_1 = showAds($advancenews['TopicAds1'], $advancenews['TopicAdsCtl']);
    if ($category_ads_1 != '') {
      ?>
      <div class="  mb-3">
        <?php echo $category_ads_1 ?>
      </div>
      <?php
    }
    ?>
    <div class="row">
      <div class="col-md-12">
          <div>
            <a href="<?php echo getTopicsUrl($this_topic) ?>">
              <h4 class="m-0 p_post_cat1"><?php echo $this_topic ?> : সর্বশেষ সংবাদ</h4>
            </a>
          </div>
      </div>
    </div>
    <?php
    $category_ads_2 = showAds($advancenews['TopicAds2'], $advancenews['TopicAdsCtl']);
    if ($category_ads_2 != '') {
      ?>
      <div class="  my-3">
        <?php echo $category_ads_2 ?>
      </div>
      <?php
    }
     $the_item_post =  getTopicsArticle($this_topic, 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['TopicAds3'], $advancenews['TopicAdsCtl']);
               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['TopicAds8'], $advancenews['TopicAdsCtl']);
   if ($category_ads_8 != '') {
     ?>
     <div class=" ">
       <?php echo $category_ads_8 ?>
     </div>
     <?php
   }
   ?>

  </div>
</section>
<script>
let page=3;
var data_type="tttop";
data_id="<?php echo $this_topic ?>";
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
?>
