<?php 
$islamic_trust_slider_arrows = get_theme_mod('islamic_trust_slider_arrows',false);
?>
<?php if ($islamic_trust_slider_arrows) : ?>
  <section id="slider">
    <div class="owl-carousel owl-theme">
      <?php 
      $islamic_trust_slide_pages = array();
      for ($islamic_trust_count = 1; $islamic_trust_count <= 4; $islamic_trust_count++) {
        $mod = absint(get_theme_mod('islamic_trust_slider_page' . $islamic_trust_count));
        if ($mod != 0) {
          $islamic_trust_slide_pages[] = $mod;
        }
      }
      if (!empty($islamic_trust_slide_pages)) :
        $islamic_trust_args = array(
          'post_type' => 'page',
          'post__in' => $islamic_trust_slide_pages,
          'orderby' => 'post__in'
        );
        $islamic_trust_query = new WP_Query($islamic_trust_args);
        if ($islamic_trust_query->have_posts()) :
          while ($islamic_trust_query->have_posts()) : $islamic_trust_query->the_post(); ?>
              <div class="item">
                <div class="slider-content-col">
                  <div class="carousel-caption">
                    <div class="inner_carousel wow fadeInUp" data-wow-delay="0.5s">
                      <?php if ( get_theme_mod( 'islamic_trust_slider_short_heading' ) ) : ?>
                        <p class="slider-top mb-1"><?php echo esc_html( get_theme_mod( 'islamic_trust_slider_short_heading' ) ); ?></p>
                      <?php endif; ?>
                      <h1 class="mb-2">
                        <a href="<?php the_permalink(); ?>">
                          <?php 
                            $islamic_trust_title = get_the_title(); 
                            $islamic_trust_words = explode(' ', $islamic_trust_title); 

                            if (count($islamic_trust_words) >= 3) {
                              // Extract the third word
                              $islamic_trust_third_word = $islamic_trust_words[2]; 
                              // Remove the third word from the original array
                              $islamic_trust_words[2] = '<span class="highlight">' . esc_html($islamic_trust_third_word) . '</span>'; 
                            }

                            // Reconstruct the title with the highlighted third word
                            $islamic_trust_modified_title = implode(' ', $islamic_trust_words);
                          ?>
                          <?php echo wp_kses_post($islamic_trust_modified_title); ?>
                        </a>
                      </h1>
                      <p class="mb-2 slider-content"><?php echo wp_kses_post(wp_trim_words(get_the_content(), 32)); ?></p>
                      <div class="more-btn mt-4">
                        <a href="<?php the_permalink(); ?>" class="text-capitalize me-lg-4 me-md-3 me-2 mb-3 slider-btn1"><?php esc_html_e('Get Started', 'islamic-trust'); ?></a>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="slider-img-col align-self-center">
                  <?php if (get_theme_mod('islamic_trust_total_yr_completed') != '') { ?>
                    <div class="counter-box">
                        <div class="text-center no-center">
                          <i class="fas fa-synagogue mb-2"></i>
                          <div class="total_yrs">
                            <?php echo esc_html(get_theme_mod('islamic_trust_total_yr_completed')) . ' ' . esc_html__('Years', 'islamic-trust'); ?>
                          </div>
                          <div class="total_yrs_text">
                            <?php esc_html_e('We Are Growing And Praying', 'islamic-trust'); ?>
                          </div>
                        </div>
                    </div>
                  <?php } ?>
                  <?php if (has_post_thumbnail()) : ?>
                    <img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_title_attribute(); ?>" />
                  <?php else : ?>
                    <div class="slider-img-color"></div>
                  <?php endif; ?>
                </div>
              </div>
          <?php endwhile;
          wp_reset_postdata();
        else : ?>
          <div class="no-postfound"><?php esc_html_e('No posts found', 'islamic-trust'); ?></div>
        <?php endif;
      endif; ?>
    </div>
    <div class="clearfix"></div>
  </section>
<?php endif; ?>
