<?php
/*
 * Template Name: Home Page
 */
get_header();
$relic_options = get_option('relic_theme_options'); ?>
<section>		
  <?php $relic_loop_active = 0;  $relic_remove_div = 0;  
  for ($relic_loop = 1; $relic_loop <= 5; $relic_loop++):
    if (get_theme_mod ( 'relic_homepage_sliderimage'.$relic_loop.'_image','')!='' ) {
      $relic_remove_div++;
    } endfor;
  ?>
<?php if ($relic_remove_div != 0) { ?>
    <div class="banner">		
      <div id="sidebar-carousel-1" class="carousel slide relic-slider" data-ride="carousel">
        <div class="carousel-inner slider">
        <?php for ($relic_loop = 1; $relic_loop <= $relic_remove_div; $relic_loop++): $relic_loop_active++;
              $relic_img = wp_get_attachment_image_src(get_theme_mod ( 'relic_homepage_sliderimage'.$relic_loop.'_image'),'full'); ?>
              <div class="item <?php echo ($relic_loop_active == 1) ? 'active' : ''; ?>">
              <?php if(get_theme_mod ( 'relic_homepage_sliderimage'.$relic_loop.'_link',$relic_options['slidelink-' . $relic_loop])) { ?>
                  <a href="<?php echo esc_url(get_theme_mod ( 'relic_homepage_sliderimage'.$relic_loop.'_link',$relic_options['slidelink-' . $relic_loop])); ?>" target="_blank">
                    <img src="<?php echo esc_url($relic_img[0]); ?>"  class="img-responsive"/>
                  </a>
                <?php } else { ?>                          
                  <img src="<?php echo esc_url($relic_img[0]); ?>" class="img-responsive"/>
              <?php } ?>	
              </div>  
          <?php  endfor; ?>                                          			
        </div>
  <?php if ($relic_loop_active >= 2) { ?>		
          <a class="left carousel-control slider_button" href="#sidebar-carousel-1" data-slide="prev">
            <i class="fa fa-arrow-circle-o-left"></i>
          </a>
          <a class="right carousel-control slider_button" href="#sidebar-carousel-1" data-slide="next">
            <i class="fa fa-arrow-circle-o-right"></i>
          </a>
  <?php } ?>
      </div>
    </div> 
<?php } ?>          
  <div class="webpage-container container not-slider">         
    <div class="recent-listings">
<?php   if (get_theme_mod ( 'relic_homepage_first_section_title_head',$relic_options['home-title'])!='') { ?>
        <div class="title">
          <h2><span><?php echo esc_html(get_theme_mod ( 'relic_homepage_first_section_title_head',$relic_options['home-title'])); ?></span></h2>			  
        </div>
        <?php } ?>
      <div class="row">
        <?php for ($relic_loop = 1; $relic_loop <= 3; $relic_loop++): 
              if (get_theme_mod ( 'relic_homepage_first_section'.$relic_loop.'_img','')!='' || get_theme_mod ( 'relic_homepage_first_section'.$relic_loop.'_title',$relic_options['section-title-' . $relic_loop])!='') { ?>
            <div class="col-md-4 col-sm-4 blog-post">
              <div class="col-md-12 no-padding-lr listing-details">
                <?php if (get_theme_mod ( 'relic_homepage_first_section'.$relic_loop.'_img','')!='') { ?>   
                  <div class="property-thumbnail">
                    <img src="<?php echo esc_url(get_theme_mod ( 'relic_homepage_first_section'.$relic_loop.'_img')); ?>" class="img-responsive" >	
                    <div class="property-excerpt">
                      <?php if(get_theme_mod ( 'relic_homepage_first_section'.$relic_loop.'_title',$relic_options['section-title-' . $relic_loop])!='') { ?>
                        <h4 class="address"><?php echo esc_html(get_theme_mod ( 'relic_homepage_first_section'.$relic_loop.'_title',$relic_options['section-title-' . $relic_loop])); ?></h4>
                      <?php } ?>
                      <?php if(get_theme_mod ( 'relic_homepage_first_section'.$relic_loop.'_desc',$relic_options['section-content-' . $relic_loop])!='') {  ?>
                        <p><?php echo wp_kses_post(get_theme_mod ( 'relic_homepage_first_section'.$relic_loop.'_desc',$relic_options['section-content-' . $relic_loop])); ?></p>
                      <?php } ?>
                    </div>
                  </div>	
        					<?php if(get_theme_mod ( 'relic_homepage_first_section'.$relic_loop.'_title',$relic_options['section-title-' . $relic_loop])!='') { ?>
        						<div class="property-details">
        						  <h4><?php echo esc_html(get_theme_mod ( 'relic_homepage_first_section'.$relic_loop.'_title',$relic_options['section-title-' . $relic_loop])); ?></h4>
        						</div>
                  <?php } ?>
				      <?php } ?>
              </div>
            </div>
        <?php }  endfor; ?>  
      </div>
    </div>                
    <div class="our-blog">
      <?php if(get_theme_mod ( 'relic_blog_title',$relic_options['post-title'])!='') { ?>
          <div class="title">
              <h2>
                 <span> <?php echo esc_html(get_theme_mod ( 'relic_blog_title',$relic_options['post-title'])); ?></span>
              </h2>
          </div>
      <?php }     
      $category= get_theme_mod ( 'relic_blogcategory',$relic_options['post-category-latest']);
          $relic_args = array(
              'cat' => $category,
              'meta_query' => array(
                  array(
                      'key' => '_thumbnail_id',
                      'compare' => 'EXISTS'
                  ),
              )
          );
      $relic_query = new $wp_query($relic_args);
      if ($relic_query->have_posts()) { ?> 
        <div id="blog_slide">
          <?php while ($relic_query->have_posts()) {
            $relic_query->the_post();
            ?>    
            <div class="owl-item col-md-6">  
              <div class="blog-box">
                <div class="blog-details col-md-4 col-xs-6"> 							
                  <?php relic_entry_meta(); ?> 											
                </div> 
                <div class="blog-img col-md-8 col-xs-6">
                  <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>    
                  <?php if (has_post_thumbnail()) { ?> 
                      <a href="<?php the_permalink(); ?>"> 
                        <?php the_post_thumbnail('relic-home-tab-size'); ?>
                      </a>
                  <?php } ?> 
                </div>
              </div>
            </div>
        <?php } ?> 
        </div>
  <?php if ($relic_query->found_posts >= 3) { ?>
          <div class="slider-button">
            <a class="blog-prev left-right" href="javascript:void(0);"> 
              <i class="fa fa-angle-left"></i> 
            </a> 
            <a class="blog-next left-right" href="javascript:void(0);"> 
              <i class="fa fa-angle-right"></i> 
            </a> 
          </div>
        <?php } ?>
<?php } ?>       
    </div>
  </div> 
</section> 
<?php get_footer(); ?>
