<?php
/*
* Template Name: Detail Page
*/
?>
<?php get_header(); ?>
<?php $template_url = get_bloginfo ( 'template_url' ) . '/'; ?>
<?php 
   //to check if there is a post regarding the url access the page
   if (have_posts ()) :
     the_post(); 
   endif;
   $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' );
   if($url != "")
   {
   $img = $url; 
   }else{
   $img = $template_url."img/acupuncturebg.jpg";
   }
?>
<?php 
$postID = get_queried_object_id();
$parent_id = $post->post_parent;
$parent_post = get_post($parent_id);
$parent_post_title = $parent_post->post_title;
?>
<!-- breadcumb -->
  <section class="z-index-common breadcumb-wrapper" style="background-image: url(<?php echo $img;?>); background-size: 100%;">
    <div class="container">
      <div class="row justify-content-between align-items-center">
        <div class="col-auto">
          <div class="breadcumb-content">
            <h1 class="breadcumb-title"><?php if(get_field('bradcamp_title') != ""){ echo get_field('bradcamp_title');}else{ the_title();}?></h1>
            <div class="breadcumb-menu-wrap">
              <ul class="breadcumb-menu">
                <li><a href="<?php echo esc_url( home_url( '/' ) ); ?>">Home</a></li>
                <li><?php if(get_field('bradcamp_title') != ""){ echo get_field('bradcamp_title');}else{ the_title();}?></li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>

  <!-- Blog Area -->
  <section class="space space-extra-bottom">
    <div class="container">
      <div class="row">
        <div class="col-lg-4 order-2 order-lg-1">
          <div class="sidebar-area">
            <div class="widget">
              <h3 class="widget_title">Other <?php echo $parent_post_title;?></h3>
              <ul class="widget_categories">
                <?php
                $args = array(
                            'post_type'      => 'page',
                            'posts_per_page' => -1,
                            'post_parent'    => $parent_id,
                            'order'          => 'DESC',
                            'orderby'        => 'menu_order'
                         );
                $query = new WP_Query($args);
                

                $post_count = $query->post_count;
                if ( $query->have_posts() ){
                $i = 1;
                  while ( $query->have_posts() ){
                    $query->the_post();
                    $img_url = get_the_post_thumbnail_url( get_the_ID(),'full');
                    $post = get_post(get_the_ID());
                ?>
                <li class="cat-item cat-item-1"><a href="<?php the_permalink();?>"><?php echo get_the_title();?></a></li>
                <?php
                   $i++;
                   }
                }
                ?>
              </ul>
            </div>
          </div>
        </div>
        <div class="col-lg-8 order-1 order-lg-2">
          <div class="vs-blog blog-single service-single">
            <div class="blog-body">
            <div class="blog-content">
              <?php echo $content = apply_filters( 'the_content', get_post_field( 'post_content', $postID ) );?>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>
  <!-- Blog Area End -->
  <?php if(have_rows('faqs',$postID)): ?>
  <section class="faq-section">
   <div class="container">
      <div class="row justify-content-center">
         <div class="section-title mb-5 wow fadeInUp" data-wow-delay="0.1s">
            <div class="sub-style">
               <h4 class="sub-title px-3 mb-0">Faqs</h4>
            </div>
            <?php the_field('faq_content',$postID);?>
         </div>
         <div class="col-lg-12">
            <div class="accordion" id="faqAccordion">
				
               <?php $i=0; while(have_rows('faqs',$postID)): ?>
                <?php the_row(); ?> 
               <div class="accordion-item">
                  <h2 class="accordion-header" id="faqHeading<?=$i?>">
                     <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#faqCollapse<?=$i?>" aria-expanded="true" aria-controls="faqCollapse<?=$i?>">
                     <?php the_sub_field('question',$postID); ?>
                     </button>
                  </h2>
                  <div id="faqCollapse<?=$i?>" class="accordion-collapse collapse <?php if($i==0){ ?> show <?php } ?>" aria-labelledby="faqHeading<?=$i?>" data-bs-parent="#faqAccordion">
                     <div class="accordion-body">
                        <?php the_sub_field('answer',$postID); ?>
                     </div>
                  </div>
               </div>
               <?php $i++; endwhile; ?>
				
            </div>
         </div>
      </div>
   </div>
</section>
<?php endif; ?>
<?php get_footer(); ?>