<?php
/**
 * Template Name: Custom Front Page
 */

get_header(); ?>

<main id="skip-content">
  <section id="top-slider">
    <?php if(get_theme_mod('charity_zone_slider_setting',true) != ''){ ?>
    <?php $charity_zone_slide_pages = array();
      for ( $ngo_non_profit_count = 1; $ngo_non_profit_count <= 3; $ngo_non_profit_count++ ) {
        $ngo_non_profit_mod = intval( get_theme_mod( 'charity_zone_top_slider_page' . $ngo_non_profit_count ));
        if ( 'page-none-selected' != $ngo_non_profit_mod ) {
          $charity_zone_slide_pages[] = $ngo_non_profit_mod;
        }
      }
      if( !empty($charity_zone_slide_pages) ) :
        $ngo_non_profit_args = array(
          'post_type' => 'page',
          'post__in' => $charity_zone_slide_pages,
          'orderby' => 'post__in'
        );
        $ngo_non_profit_query = new WP_Query( $ngo_non_profit_args );
        if ( $ngo_non_profit_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="owl-carousel" role="listbox">
      <?php  while ( $ngo_non_profit_query->have_posts() ) : $ngo_non_profit_query->the_post(); ?>
        <div class="slider-box">
          <?php if(has_post_thumbnail()){
            the_post_thumbnail();
            } else{?>
            <img src="<?php echo esc_url(get_theme_file_uri()); ?>/assets/img/slider.png" alt="" />
          <?php } ?>
          <div class="slider-inner-box">
            <?php if(get_theme_mod('charity_zone_slider_title_setting',1) == 1){ ?>
              <a href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a>
            <?php }?>
            <?php if(get_theme_mod('charity_zone_slider_content_setting',1) == 1){ ?>
              <p class="mb-2"><?php echo esc_html( wp_trim_words( get_the_content(), esc_attr(get_theme_mod('charity_zone_slider_excerpt_length', 40)) )); ?></p>
            <?php }?>
            <?php if(get_theme_mod('ngo_non_profit_slider_button_setting',1) == 1 && get_theme_mod('ngo_non_profit_slider_button_text','Get Involved') != ''){ ?>
              <div class="donate-btn text-center">
                <a href="<?php the_permalink(); ?>"><?php esc_html_e(get_theme_mod('ngo_non_profit_slider_button_text','Get Involved')); ?></a>
              </div>
            <?php }?>
          </div>
        </div>
      <?php $i++; endwhile;
      wp_reset_postdata();?>
    </div>
    <?php else : ?>
      <div class="no-postfound"></div>
    <?php endif;
    endif;?>
    <?php } ?>
  </section>

  <?php if(get_theme_mod('charity_zone_services_setting',true) != ''){ ?>
  <section id="serve-sec">
    <div class="container">
      <div class="row">
        <?php
          $charity_zone_catData = get_theme_mod('charity_zone_services','services');
          if($charity_zone_catData){
            $charity_zone_page_query = new WP_Query(array( 'category_name' => esc_html($charity_zone_catData,'ngo-non-profit'), 'posts_per_page' => 3,));
            while( $charity_zone_page_query->have_posts() ) : $charity_zone_page_query->the_post(); ?>
              <div class="col-lg-4 col-md-4">
                <div class="serv-box text-center mb-4 mb-md-0">
                  <h4><?php the_title(); ?></h4>
                  <p><?php $charity_zone_excerpt = get_the_excerpt(); echo esc_html( charity_zone_string_limit_words( $charity_zone_excerpt,8 ) ); ?></p>
                  <div class="donate-btn text-center">
                    <a href="<?php the_permalink(); ?>"><?php esc_html_e('Read More','ngo-non-profit'); ?></a>
                  </div>
                </div>
              </div>
            <?php endwhile;
            wp_reset_postdata();
          } ?>
      </div>
    </div>
  </section>
<?php } ?>

<?php if(get_theme_mod('charity_zone_about_setting',true) != ''){ ?>
  <section id="about_sec">
    <div class="container">
      <?php $charity_zone_about_pages = array();
        $ngo_non_profit_mod = intval( get_theme_mod( 'charity_zone_about_page' ));
        if ( 'page-none-selected' != $ngo_non_profit_mod ) {
          $charity_zone_about_pages[] = $ngo_non_profit_mod;
        }
        if( !empty($charity_zone_about_pages) ) :
          $ngo_non_profit_args = array(
            'post_type' => 'page',
            'post__in' => $charity_zone_about_pages,
            'orderby' => 'post__in'
          );
          $ngo_non_profit_query = new WP_Query( $ngo_non_profit_args );
          if ( $ngo_non_profit_query->have_posts() ) :
      ?>
      <?php  while ( $ngo_non_profit_query->have_posts() ) : $ngo_non_profit_query->the_post(); ?>
        <div class="row">
          <div class="col-lg-6 col-md-6 align-self-center">
            <div class="about-inner-box">
              <h3><?php the_title(); ?></h3>
              <p><?php the_excerpt(); ?></p>
              <div class="donate-btn">
                <a href="<?php the_permalink(); ?>"><?php esc_html_e('Donate Now','ngo-non-profit'); ?></a>
              </div>
            </div>
          </div>
          <div class="col-lg-6 col-md-6 align-self-center">
            <?php if(has_post_thumbnail()){
            the_post_thumbnail();
            } else{?>
            <img src="<?php echo esc_url(get_theme_file_uri()); ?>/assets/img/slider.png" alt="" />
          <?php } ?>
          </div>
        </div>
      <?php $i++; endwhile;
      wp_reset_postdata();?>
      <?php else : ?>
        <div class="no-postfound"></div>
      <?php endif;
      endif;?>
    </div>
  </section>
<?php } ?>

</main>

<?php get_footer(); ?>
