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

get_header(); ?>

<main id="skip_content" role="main">
  <?php do_action( 'automobile_car_dealer_above_slider' ); ?>

  <?php if( get_theme_mod('automobile_car_dealer_slider_hide',false) != '' || get_theme_mod( 'automobile_car_dealer_display_slider',true) != ''){ ?>
    <section id="slider" class="mw-100 m-auto p-0">
      <div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel"> 
        <?php $automobile_car_dealer_slider_page = array();
          for ( $count = 1; $count <= 4; $count++ ) {
            $mod = intval( get_theme_mod( 'automobile_car_dealer_slider' . $count ));
            if ( 'page-none-selected' != $mod ) {
              $automobile_car_dealer_slider_page[] = $mod;
            }
          }
          if( !empty($automobile_car_dealer_slider_page) ) :
          $args = array(
            'post_type' => 'page',
            'post__in' => $automobile_car_dealer_slider_page,
            'orderby' => 'post__in'
          );
          $query = new WP_Query( $args );
          if ( $query->have_posts() ) :
            $i = 1;
        ?>     
          <div class="carousel-inner" role="listbox">
            <?php  while ( $query->have_posts() ) : $query->the_post(); ?>
              <div <?php if($i == 1){echo 'class="carousel-item active"';} else{ echo 'class="carousel-item"';}?>>
                <?php if(has_post_thumbnail()){
                  the_post_thumbnail();
                } else{?>
                  <img src="<?php echo esc_url(get_template_directory_uri()); ?>/images/slider.png" alt="<?php echo esc_attr( 'slider', 'automobile-car-dealer'); ?>" />
                <?php } ?>
                <div class="carousel-caption wow zoomIn">
                  <div class="inner_carousel text-center">
                    <?php if( get_theme_mod('automobile_car_dealer_slider_heading',true) != ''){ ?>
                      <h1 class="p-0 text-uppercase"><?php the_title(); ?></h1>
                    <?php } ?>
                    <?php if( get_theme_mod('automobile_car_dealer_slider_text',true) != ''){ ?>
                      <p class="my-2 mx-0"><?php $automobile_car_dealer_excerpt = get_the_excerpt(); echo esc_html( automobile_car_dealer_string_limit_words( $automobile_car_dealer_excerpt, esc_attr(get_theme_mod('automobile_car_dealer_slider_excerpt_number','30')))); ?></p>
                    <?php } ?>
                    <?php if (get_theme_mod( 'automobile_car_dealer_show_slider_button',true) != '' || get_theme_mod( 'automobile_car_dealer_display_slider_button',true) != ''){ ?>
                      <?php if( get_theme_mod('automobile_car_dealer_slider_button_text','READ MORE') != ''|| get_theme_mod('automobile_car_dealer_slider_button_link') != ''){ ?>
                        <div class="slide-button mt-md-3 mt-0">
                          <a class="read-more" href="<?php echo esc_url(get_theme_mod('automobile_car_dealer_slider_button_link')!= '') ? esc_url(get_theme_mod('automobile_car_dealer_slider_button_link')) : esc_url(get_permalink()); ?>"><i class="<?php echo esc_attr(get_theme_mod('automobile_car_dealer_slider_button_icon','fas fa-long-arrow-alt-right')); ?> p-2 me-2"></i><?php echo esc_html( get_theme_mod('automobile_car_dealer_slider_button_text',__('READ MORE','automobile-car-dealer'))); ?><span class="screen-reader-text"><?php echo esc_html( get_theme_mod('automobile_car_dealer_slider_button_text',__('READ MORE','automobile-car-dealer'))); ?></span></a>
                        </div> 
                      <?php }?>  
                    <?php } ?>
                  </div>
                </div>
              </div>
            <?php $i++; endwhile; 
            wp_reset_postdata();?>
          </div>
        <?php else : ?>
          <div class="no-postfound"></div>
        <?php endif;
        endif;?>
        <a class="carousel-control-prev" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev" role="button">
          <span class="carousel-control-prev-icon w-auto h-auto" aria-hidden="true"><i class="<?php echo esc_attr(get_theme_mod('automobile_car_dealer_slider_previous_icon','fas fa-chevron-left')); ?>" ></i></span>
          <span class="screen-reader-text"><?php esc_html_e( 'Previous','automobile-car-dealer' );?></span>
        </a>
        <a class="carousel-control-next" data-bs-target="#carouselExampleCaptions" data-bs-slide="next" role="button">
          <span class="carousel-control-next-icon w-auto h-auto" aria-hidden="true"><i class="<?php echo esc_attr(get_theme_mod('automobile_car_dealer_slider_next_icon','fas fa-chevron-right')); ?>" ></i></span>
          <span class="screen-reader-text"><?php esc_html_e( 'Next','automobile-car-dealer' );?></span>
        </a>
      </div>  
      <div class="clearfix"></div>
    </section> 
  <?php }?>

  <?php do_action( 'automobile_car_dealer_above_project' ); ?>

  <?php if(get_theme_mod('automobile_car_dealer_display_about_sec',false) != ''){ ?>
    <?php if( get_theme_mod('automobile_car_dealer_sec_title') != '' || get_theme_mod( 'automobile_car_dealer_project_single_post' )!= '' ||get_theme_mod('automobile_car_dealer_project_category') != ''){ ?>
      <section id="project" class="my-lg-5 my-3 wow bounceIn">
        <div class="container">
          <?php if( get_theme_mod('automobile_car_dealer_sec_title') != ''){ ?>
            <h2><i class="fas fa-car me-2"></i><?php echo esc_html(get_theme_mod('automobile_car_dealer_sec_title','')); ?></h2>
          <?php }?>
          <div class="row m-0">
            <div class="col-md-7 col-sm-12 p-0">
              <?php
              $automobile_car_dealer_postData =  get_theme_mod('automobile_car_dealer_project_single_post');
              if($automobile_car_dealer_postData){
                $args = array( 'name' => esc_html($automobile_car_dealer_postData ,'automobile-car-dealer'));
              $query = new WP_Query( $args );
              if ( $query->have_posts() ) :
                while ( $query->have_posts() ) : $query->the_post(); ?>
                  <div class="mainbox">
                    <p class="mb-2"><?php $automobile_car_dealer_excerpt = get_the_excerpt(); echo esc_html( automobile_car_dealer_string_limit_words( $automobile_car_dealer_excerpt, esc_attr(get_theme_mod('automobile_car_dealer_about_excerpt_number','25')))); ?></p>
                    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?><span class="screen-reader-text"><?php the_title(); ?></span></a>
                  </div>
                <?php endwhile; 
              wp_reset_postdata();?>
              <?php else : ?>
                <div class="no-postfound"></div>
              <?php
              endif;} ?>
              <div class="clearfix"></div>
            </div>
            <div class="col-md-5 col-sm-12">
              <?php 
                $catData=  get_theme_mod('automobile_car_dealer_project_category');
                if($catData){
                  $page_query = new WP_Query(array( 'category_name' => esc_html( $catData ,'automobile-car-dealer')));?>
                <?php while( $page_query->have_posts() ) : $page_query->the_post(); ?>
                  <div class="categorybox row mb-3 py-2 px-0">
                    <div class="col-md-4 col-sm-4">
                      <?php if(has_post_thumbnail()) { ?><?php the_post_thumbnail(); ?><?php } ?>
                    </div>
                    <div class="col-md-8 col-sm-8">
                      <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?><span class="screen-reader-text"><?php the_title(); ?></span></a></h3>
                      <p><?php $automobile_car_dealer_excerpt = get_the_excerpt(); echo esc_html( automobile_car_dealer_string_limit_words( $automobile_car_dealer_excerpt, esc_attr(get_theme_mod('automobile_car_dealer_category_excerpt_number','15')))); ?></p>
                    </div>
                  </div>
                <?php endwhile;
                wp_reset_postdata();
              }?>
            </div>
          </div>
        </div> 
      </section>
    <?php }?>
  <?php }?>

  <?php do_action( 'automobile_car_dealer_above_content' ); ?>

  <div class="container">
    <?php while ( have_posts() ) : the_post(); ?>
      <div class="new-text"><?php the_content(); ?></div>
    <?php endwhile; // end of the loop. ?>
  </div>
</main>

<?php get_footer(); ?>