<?php
/**
 * The Template Name: Home Page
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package Mediquip Plus
 */

get_header(); ?>

<div id="content">
  <?php
    $mediquip_plus_hidcatslide = get_theme_mod('mediquip_plus_hide_categorysec', false);
    $mediquip_plus_slidersection = get_theme_mod('mediquip_plus_slidersection');

    if ($mediquip_plus_hidcatslide && $mediquip_plus_slidersection) { ?>
    <section id="catsliderarea">
      <div class="catwrapslider">
        <div class="owl-carousel">
          <?php if( get_theme_mod('mediquip_plus_slidersection',false) ) { ?>
          <?php $mediquip_plus_queryvar = new WP_Query('cat='.esc_attr(get_theme_mod('mediquip_plus_slidersection',false)));
            while( $mediquip_plus_queryvar->have_posts() ) : $mediquip_plus_queryvar->the_post(); ?>
              <div class="slidesection"> 
                <?php if(has_post_thumbnail()){
                  the_post_thumbnail('full');
                  } else{?>
                  <img src="<?php echo esc_url(get_template_directory_uri()); ?>/images/slider.png" alt="<?php echo esc_attr( 'slider', 'mediquip-plus'); ?>"/>
                <?php } ?>
                <div class="slider-box">
                  <h1><a href="<?php echo esc_url( get_permalink() );?>"><?php the_title(); ?></a></h1>
                  <div class="shop-now">
                    <?php 
                    $mediquip_plus_button_text = get_theme_mod('mediquip_plus_button_text', 'SHOP NOW');
                    $mediquip_plus_button_link_slider = get_theme_mod('mediquip_plus_button_link_slider', ''); 
                    if (empty($mediquip_plus_button_link_slider)) {
                        $mediquip_plus_button_link_slider = get_permalink();
                    }
                    if ($mediquip_plus_button_text || !empty($mediquip_plus_button_link_slider)) { ?>
                      <?php if(get_theme_mod('mediquip_plus_button_text', 'SHOP NOW') != ''){ ?>
                        <a href="<?php echo esc_url($mediquip_plus_button_link_slider); ?>">
                          <?php echo esc_html($mediquip_plus_button_text); ?>
                            <span class="screen-reader-text"><?php echo esc_html($mediquip_plus_button_text); ?></span>
                        </a>
                      <?php } ?>
                    <?php } ?>
                  </div>
                </div>
              </div>
            <?php endwhile; wp_reset_postdata(); ?>
          <?php } ?>
        </div>
      </div>
      <div class="clear"></div>
    </section>
  <?php } ?>

<?php
    $mediquip_plus_hidcatfacility = get_theme_mod('mediquip_plus_hidcatfacility', false);
    $mediquip_plus_facilities_section = get_theme_mod('mediquip_plus_facilities_section');

    if ($mediquip_plus_hidcatfacility && $mediquip_plus_facilities_section) { ?>
  <section id="second-sec" class="text-center">
    <div class="container">
      <?php if ( get_theme_mod('mediquip_plus_section_title') != "") { ?>
        <h2><?php echo esc_html(get_theme_mod('mediquip_plus_section_title','')); ?></h2>
        <hr class="line-hr">
        <div class="line-box mb-4"><i class="fas fa-heartbeat"></i></div>
      <?php } ?>
      <div class="inner-main-box">
        <div class="row">
          <?php if( get_theme_mod('mediquip_plus_facilities_section',false) ) { ?>
          <?php $mediquip_plus_queryvar = new WP_Query('cat='.esc_attr(get_theme_mod('mediquip_plus_facilities_section',false)));
            while( $mediquip_plus_queryvar->have_posts() ) : $mediquip_plus_queryvar->the_post(); ?>
              <div class="col-lg-4 col-md-4">
                <div class="inner-service-box"> 
                  <?php the_post_thumbnail( 'full' ); ?>
                  <div class="title-box">
                    <h3><a href="<?php echo esc_url( get_permalink() );?>"><?php the_title(); ?></a></h3>
                    <?php
                      $trimexcerpt = get_the_excerpt();
                      $shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 20 );
                      echo '<p>' . esc_html( $shortexcerpt ) . '</p>'; 
                    ?>
                    <a href="<?php the_permalink(); ?>"><?php esc_html_e('Read More','mediquip-plus'); ?></a>
                  </div>
                </div>
              </div>
            <?php endwhile; wp_reset_postdata(); ?>
          <?php } ?>
        </div>
      </div>
    </div>
  </section>
<?php } ?>

  <section id="content-creation">
    <div class="container">      
      <?php while ( have_posts() ) : the_post(); ?>
        <?php the_content(); ?>
      <?php endwhile; // end of the loop. ?>
    </div>
  </section>
</div>

<?php get_footer(); ?>