<?php
/*
Template Name:CMS-template
*/
?>
<?php get_header(); ?>
<div id="core" class="container_home_page article-template <?php if(empty(get_the_post_thumbnail()) ) { echo "no_feature";} ?>">
    <div class="main_img">      
        <div class="cms-slider">
            <div class="top-slider">
               
                <?php
                    if ( have_rows('slider_images') ) {
                        while ( have_rows('slider_images') ) {
                        the_row();
                       $slide_image = get_sub_field('slide_image');
                        ?>
                        <div> 
                         <img src="<?php echo esc_url($slide_image['url']); ?>" alt="<?php echo esc_attr($slide_image['alt']); ?>" />
                        </div>
                        <?php
                      
                        }
                    }
                      else{       
                       the_post_thumbnail( 'full' );                        
                    }
                ?>

            </div>
        </div>
    </div>
<?php
$menu = get_term( $locations['primary'], 'nav_menu' );
$array_menu = wp_get_nav_menu_items(13);
$menu = array();
foreach ($array_menu as $m) {
    if (empty($m->menu_item_parent)) {
        $menu[$m->ID] = array();
        $menu[$m->ID]['ID'] = $m->ID;
        $menu[$m->ID]['title'] = $m->title;
        $menu[$m->ID]['url'] = $m->url;
        $menu[$m->ID]['children'] = array();
    }
}
$submenu = array();
foreach ($array_menu as $m) {
    if ($m->menu_item_parent) {
        $submenu[$m->ID] = array();
        $submenu[$m->ID]['ID'] = $m->ID;
        $submenu[$m->ID]['title'] = $m->title;
        $submenu[$m->ID]['url'] = $m->url;
        $menu[$m->menu_item_parent]['children'][$m->ID] = $submenu[$m->ID];
    }
}
   /*echo '<pre>';
   print_r($menu);
   echo '</pre>';  */ 
   
global $wp;  
$current_url = home_url(add_query_arg(array($_GET), $wp->request));

$results = searcharray($current_url."/", 'url', $menu);
 
function searcharray($value, $key, $array) {
    //echo "===value==".$value."==Key==".$key."==";
   foreach ($array as $k => $val) {
        foreach ($val['children'] as $sub_k => $sub_val) {
           if ($sub_val[$key] == $value) {
               return $k;
           }
       }
   }
   return null;
}
        
?>
<div class="inner-page-section2">
        <div class="container">
            <div class="news-detail-bx">
                <div class="left_column">
                 <span class="gen_heading"><?php echo $menu[$results]['title']; ?></span>
                    <div class="mid-panel">
                     <span class="gen_txt">Also in this section</span>
                     
                
                         <?php foreach ($menu[$results]['children'] as $key => $sub_val) {
                               ?>
                         <?php  $post_url   = $sub_val['url'];
                         $page_url = explode("#",$post_url);
                         $post_title    = $sub_val['title'];?> 
                             <div class="latest_news">
                                <a href="<?php echo $post_url;?>" class="<?php if($page_url[0] == $current_url."/"){ echo "active"; }?>"><span class="gen_title"> 
                                    <?php echo $post_title; ?>
                                    </span> <span class="arrow"><img src="<?php echo bloginfo('template_url');?>/assets/images/news-arrow.svg"></span></a>
                                 </div>
                                 
                         <?php }?>
                     </div> 
                </div>
                
                
                
                <div class="right_column">
           <h1 class="page-title"><?php the_title();?></h1>
                <?php
            if( have_rows('content_area_section') ):

    while ( have_rows('content_area_section') ) : the_row();
  if( get_row_layout() == 'content' ):?>
          <div class="Content_area default-section cms-section"><?php echo get_sub_field('content');?></div>
          <?php elseif( get_row_layout() == 'committee_formation' ): ?>

            <div class="information-bx default-section">
              <div class="committe_text"><h2 class="cm-heading"><?php echo get_sub_field('text');?></h2></div>
              <div class="content_section"><?php echo get_sub_field('content_section');?></div>
            </div>
       <?php elseif( get_row_layout() == 'general_message' ): ?>
         <div class="general_message default-section"><?php echo get_sub_field('content');?></div>
            <?php elseif( get_row_layout() == 'gallary_section' ): ?>
           <div class="slider-section default-section">   
               <div class="slider-part">
                    <?php while ( have_rows('gallary_image') ) : the_row();
                        $slider_image = get_sub_field('image');?>    
                        <div class="banner-part">
                     <?php echo wp_get_attachment_image($slider_image['id'], array('700', '600'),false, array( "class" => "" ) );?> 
                            </div>
                    <?php endwhile;?>
                    </div>
        </div>
    <?php elseif( get_row_layout() == 'programme_section' ): ?>
            <div class="program-section default-section">
              <div class="programme_title"><h2 class="cm-heading"><strong><?php echo get_sub_field('title');?></strong></h2></div>
              <div class="content_area"><?php echo get_sub_field('content_area');?></div>
            </div>
            <?php elseif( get_row_layout() == 'download_section' ): ?>
         <?php $pdf = get_sub_field('download_file');?>

         <div class="download-section default-section">
             <div class="left-part">
               <div class="download_pdf"><a href="<?php echo $pdf?>"><img src="<?php echo bloginfo('template_url');?>/images/download-icon.svg" alt="download-icon"></a> </div>
             </div>

             <div class="right-part">
                <div class="heading"><h2 class="gen-heading"><?php echo get_sub_field('heading');?></h2> </div>
                <div class="sub_heading"><?php echo get_sub_field('subheading');?></div>
             </div>

         </div>
         <?php elseif( get_row_layout() == 'simple_download_section' ): ?>
         <?php $pdf = get_sub_field('simple_upload_file');?>

         <div class="simple-download-section default-section">
             <div class="download_button"><a href="<?php echo $pdf?>"><?php echo get_sub_field('heading');?></a> </div>
         </div>
            <?php elseif( get_row_layout() == 'accordian_section' ): ?>
              <div class="accodion-section default-section">

              
            <div class="accordian_title"><h2 class="accordion-heading"><?php echo get_sub_field('section_title');?></h2></div>
         <ul>  
            <?php if ( have_rows( 'accordion' ) ) : ?>
    <?php while ( have_rows( 'accordion' ) ) : the_row() ?>
    <li>  
      <div class="accord-title">
          <h3 class="acc-heading"><?php the_sub_field( 'panel_title' ); ?></h3>
      <span class="caret-icon"><img src="<?php echo bloginfo('template_url');?>/assets/images/news-arrow.svg"> </span>
        </div>
        <div class="accor-bx">
            <p> <?php the_sub_field( 'panel_content' ); ?> </p>
        </div>
    </li>
        <?php endwhile; ?>

            </ul> 
          </div>
 

<?php endif;?>
            
            
            
<?php
        endif;

   
    endwhile; 

else :
   endif;   ?>  
            </div>
    </div>
  
      </div>
</div>



  <script>
$('.slider-part').slick({
    dots: true,
   infinite: true,
  slidesToShow: 1,
  slidesToScroll: 1,
 responsive: [
    {
      breakpoint: 768,
      settings: {
        arrows: false,
        dots: true,
        infinite: true,
        slidesToShow: 1,
        slidesToScroll: 1,
      }
    },
    {
      breakpoint: 480,
      settings: {
        dots: true,
        infinite: true,
        slidesToShow: 1,
        slidesToScroll: 1,
      }
    }
  ]
});
</script>
<script>
if($(".nivoSlider").children().length === 1)
    $("nivo-prevNav, nivo-nextNav").hide(0);
        
</script>
<script>
     $(document).ready(function(){
        $('.accord-title').click(function(){
            $('.accord-title.active').not(this).removeClass('active').next().slideToggle('slow');
            $(this).next('.accor-bx').slideToggle('slow');
            $(this).toggleClass('active');
        });
     });
     $("a[href^='#']").on('click', function(e) {
         e.preventDefault();
         var hash = this.hash;
         $('html, body').animate({
             scrollTop: $(hash).offset().top
           }, 1000, function(){
             window.location.hash = hash;
           });
      });



//cms-slider
$('.top-slider').slick({
    dots: false,
    infinite: false,
    fade: true,
    autoplay:true,
    speed: 900,
    arrows:true,
    slidesToShow: 1,
    slidesToScroll: 1
}); 
//Product slider

 </script>
 <?php get_footer(); ?>
