<?php
get_header();
$term = get_queried_object();
$tid  = absint( $term->term_id );
?>
<main id="main-content">
<section class="lt-page-hero"><div class="lt-container">
<?php lt_theme_breadcrumbs(); ?>
<div class="lt-kicker"><?php echo esc_html( function_exists('lt_core_label') ? lt_core_label('sectors',__('Sectors','law-temple-theme')) : __('Sectors','law-temple-theme') ); ?></div>
<h1><?php single_term_title(); ?></h1>
<?php if ( $term->description ) : ?><p class="lt-lead"><?php echo esc_html( $term->description ); ?></p><?php endif; ?>
</div></section>
<?php
$groups = array(
    'practice' => __( 'Relevant expertise', 'law-temple-theme' ),
    'lawyer'   => __( 'People', 'law-temple-theme' ),
    'insight'  => __( 'Insights', 'law-temple-theme' ),
    'matter'   => __( 'Representative matters', 'law-temple-theme' ),
);
foreach ( $groups as $type => $heading ) :
    $q = new WP_Query( array(
        'post_type'=>$type,
        'post_status'=>'publish',
        'posts_per_page'=>6,
        'tax_query'=>array( array( 'taxonomy'=>'sector', 'field'=>'term_id', 'terms'=>$tid ) ),
        'orderby'=> 'insight' === $type ? 'date' : 'menu_order title',
        'order'=> 'insight' === $type ? 'DESC' : 'ASC',
    ) );
    if ( ! $q->have_posts() ) { continue; }
    ?>
    <section class="lt-section <?php echo 'insight' === $type ? 'lt-section--surface' : ''; ?>"><div class="lt-container">
        <h2><?php echo esc_html( $heading ); ?></h2><div class="lt-grid">
        <?php while ( $q->have_posts() ) : $q->the_post(); lt_theme_archive_card( get_the_ID(), $type ); endwhile; ?>
        </div>
    </div></section>
    <?php wp_reset_postdata();
endforeach;
lt_theme_global_cta();
?>
</main>
<?php get_footer(); ?>
