<?php

// Taxonomy List Component
$list_query = mtm_taxonomy_query('list');
$taxonomy = mtm_acf_taxonomy_property('list', 'taxonomy');
$terms = mtm_acf_taxonomy_property('list', 'slug');
$view = _get_field('mtm_show_view_all_link');
?>

<h2 class="h1"><?php 
the_title();
edit_post_link('(Edit)', ' • ');
?>
</h2>
<div <?php 
post_class('mtm-component--main');
?>
>
	<?php 
mtm_get_template_part('mtm-content', 'component-page');
?>
</div>

<?php 
if (_get_field('mtm_show_taxonomy_links')) {
    mtm_terms_from_taxonomy_links($taxonomy);
    // output taxonomy links
}
?>

<?php 
<?php

// Taxonomy Grid
$grid_query = mtm_taxonomy_query('grid');
$taxonomy = mtm_acf_taxonomy_property('grid', 'taxonomy');
?>

<div <?php 
post_class('mtm-component--main');
?>
>
	<?php 
mtm_get_template_part('mtm-content', 'component-page');
?>
	<?php 
if (_get_field('mtm_show_taxonomy_links')) {
    mtm_terms_from_taxonomy_links($taxonomy);
    // output taxonomy
}
?>
</div>

<?php 
if ($grid_query->have_posts()) {
    ?>

	<div class="mtm-component--content mtm-grid--wrapper">
		<div class="gallery-dynamic-row" >

			<?php 
    while ($grid_query->have_posts()) {
<?php

// Featured News Story Logic
// Latest Post
if ("Latest Post" == _get_field('mtm_home_select_featured_story_source')) {
    $posttype = get_field('mtm_home_select_featured_story_type');
    $news_post_query = mtm_page_component_post_query($posttype, 1);
    while ($news_post_query->have_posts()) {
        $news_post_query->the_post();
        mtm_get_template_part('mtm-content', 'home-featured-story');
    }
    // Latest Taxonomy Post
} elseif ("Latest Post From Taxonomy" == _get_field('mtm_home_select_featured_story_source')) {
    $news_tax_query = mtm_taxonomy_query('home_featured_story', 1);
    while ($news_tax_query->have_posts()) {
        $news_tax_query->the_post();
        mtm_get_template_part('mtm-content', 'home-featured-story');
    }
    // Specific Post
} elseif ("Specific Post" == _get_field('mtm_home_select_featured_story_source')) {
    $post_object = get_field('mtm_home_featured_story_select_single');
    if ($post_object) {
        $post = $post_object;
        setup_postdata($post);
        mtm_get_template_part('mtm-content', 'home-featured-story');
    }
}