<?php

/*
 * Template name: Exhibitions and Activities
 *
 * @package far_loop
 *
 */

get_header();

$fields = array_fill_keys( array('sections'), null);

foreach ( $fields as $field => $value ){
    $fields[$field] = get_field($field);
}


$agenda = get_page_by_path( 'agenda' );

$_section = get_field('sections', false, false);
?>

<div class="u_pt-3 u_pt-md-6">
    <div id="mainContainer" class="l_container u_mv-5">
        <div class="grid u_mh-min1 u_mb-3 u_mb-md-0">
            <div class="col--md--one--half u_ph-1">
                <!-- page-title module-->
                <div class="page-title u_mb-3 u_mb-md-4">
                    <!-- Page title-->
                    <h1 class="page-title__apex-title u_mb-0p5"><?php the_title();?></h1>
                </div>
                <div class="u_mt-min1p5">
                    <!-- share-module-->
                    <?php share_module();?>
                </div>
            </div>
            <div class="col--md--one--half u_ph-1">
                <?php if ( !empty( $fields['sections'] ) ) :?>
                <ul class="same-page-nav">
                <?php foreach ( $fields['sections'] as $section ) : ?>
                    <li class="same-page-nav__item"><a href="#<?php echo sanitize_title( $section['title'] );?>" data-soft-scroll="#<?php echo sanitize_title( $section['title'] );?>" class="same-page-nav__link"><?php echo $section['title'];?></a></li>
                <?php endforeach; // section ?>
                </ul>
                <?php endif; //sections ?>
            </div>
        </div>
      
      
    <?php
    if( isset($_section) ){
        foreach( $_section as $k=>$v ){
            echo '
                <div id="'.sanitize_title($v['field_57229645366d5']).'" class="u_mb-7">
                    <h3 class="section-heading delta"><span class="u_text-underline">'.$v['field_57229645366d5'].'</span></h3>
            ';
            if( is_array($v['field_572296a2366d7']) ){
                foreach( $v['field_572296a2366d7'] as $kk=>$vv ){
                    activity_thumb($vv);
                }
            }

            if( !empty($v['field_5722964b366d6']) ){
                $cat = get_term($v['field_5722964b366d6'], 'activity-type');
                $l_url = esc_url(add_query_arg('activity-type', $cat->slug, get_permalink($agenda)));
                echo '
                    <div class="u_mt-min2">
                        <a href="'.$l_url.'" class="button">'.sprintf(__('View in agenda &mdash; %s', 'far_loop'), $v['field_57229645366d5']).'</a>
                    </div>
                ';
            }
            echo '
                </div>
            ';
        }
    }
    ?>

    </div>
</div>

<?php

get_footer();
