<?php 
$expert_ngo_volunteer_slider = get_theme_mod('expert_ngo_volunteer_slider_setting', true);

if ($expert_ngo_volunteer_slider == '1') :
?>

<section id="slider-section" class="slider-area">
  <div class="slider-content">
    <div id="owl-carousel" class="owl-carousel owl-theme">
        <?php 
        $expert_ngo_volunteer_pages = array();
        for ($expert_ngo_volunteer_count = 1; $expert_ngo_volunteer_count <= 3; $expert_ngo_volunteer_count++) {
            $expert_ngo_volunteer_mod = intval(get_theme_mod('expert_ngo_volunteer_slider' . $expert_ngo_volunteer_count));
            if ('page-none-selected' != $expert_ngo_volunteer_mod) {
                $expert_ngo_volunteer_pages[] = $expert_ngo_volunteer_mod;
            }
        }

        if (!empty($expert_ngo_volunteer_pages)) :
            $args = array(
                'post_type' => 'page',
                'post__in' => $expert_ngo_volunteer_pages,
                'orderby' => 'post__in'
            );
            $query = new WP_Query($args);
            if ($query->have_posts()) :
                while ($query->have_posts()) : $query->the_post(); ?>
                    <div class="item">
                            <div class="row">
                                <div class="col-lg-6 col-md-5 align-self-center">
                                    <div class="carousel-caption">
                                        <div class="inner_carousel pe-lg-5 wow fadeInUp" data-wow-delay="0.5s">
                                            <?php
                                            $expert_ngo_volunteer_slider_text = get_theme_mod('expert_ngo_volunteer_slider_text');
                                            if ($expert_ngo_volunteer_slider_text != '') { ?>
                                                <p class="mb-3 slider-top-text"><?php echo esc_html(apply_filters('expert_ngo_volunteer_topheader', $expert_ngo_volunteer_slider_text)); ?></p>
                                            <?php } ?>
                                            <?php
                                            $expert_ngo_volunteer_title = get_the_title();
                                            $expert_ngo_volunteer_title_words = explode(' ', $expert_ngo_volunteer_title);

                                            if (count($expert_ngo_volunteer_title_words) >= 5) {
                                                // Extract the first three words
                                                $expert_ngo_volunteer_first_part = implode(' ', array_slice($expert_ngo_volunteer_title_words, 0, 3));
                                                // Extract the 4th and 5th words
                                                $expert_ngo_volunteer_red_words = implode(' ', array_slice($expert_ngo_volunteer_title_words, 3, 2));
                                                // Extract the remaining part of the title after the 5th word
                                                $expert_ngo_volunteer_last_part = implode(' ', array_slice($expert_ngo_volunteer_title_words, 5));
                                            } else {
                                                // If the title has fewer than 5 words, just display it as is
                                                $expert_ngo_volunteer_first_part = $expert_ngo_volunteer_title;
                                                $expert_ngo_volunteer_red_words = '';
                                                $expert_ngo_volunteer_last_part = '';
                                            }
                                            ?>
                                            <h1 class="mb-3">
                                                <a href="<?php the_permalink(); ?>">
                                                    <?php echo esc_html($expert_ngo_volunteer_first_part); ?>
                                                    <?php if (!empty($expert_ngo_volunteer_red_words)) : ?>
                                                        <span class="highlight-red"><?php echo esc_html($expert_ngo_volunteer_red_words); ?></span>
                                                    <?php endif; ?>
                                                    <?php echo esc_html($expert_ngo_volunteer_last_part); ?>
                                                </a>
                                            </h1>
                                            <p><?php echo esc_html(wp_trim_words(get_the_content(), '35')); ?></p>
                                            <div class="read-btn mt-md-4 mt-3">
                                                <a href="<?php the_permalink(); ?>"><?php echo esc_html('Get Started', 'expert-ngo-volunteer'); ?></a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-6 col-md-7 slider-img-col position-relative wow zoomInUp" data-wow-delay="0.5s">
                                    <div class="sliderimg">
                                        <?php if (has_post_thumbnail()) { ?>
                                            <img src="<?php the_post_thumbnail_url(''); ?>"/>
                                        <?php } else { ?>
                                            <div class="slider-color-box"></div>
                                        <?php } ?>
                                    </div>
                                     <?php if (get_theme_mod('expert_ngo_volunteer_total_no_charity_experience') != '10+ years') { ?>
                                        <div class="text-center no-center">
                                            <i class="fas fa-hand-holding-usd"></i><div class="total-yrs mb-2"><?php echo esc_html(get_theme_mod('expert_ngo_volunteer_total_no_charity_experience', '')); ?></div>
                                            <div class="experience-text"><?php esc_html_e('We Are Crowing And Helping', 'expert-ngo-volunteer'); ?></div>
                                        </div>
                                    <?php } ?>
                                </div>
                            </div>
                    </div>
                <?php endwhile;
                wp_reset_postdata();
            else : ?>
                <div class="no-postfound"></div>
            <?php endif;
        endif; ?>
    </div>
  </div>
</section>
<?php endif; ?>