$display = get_field('mtm_home_stories_per_topic');
$mtm_news_feature_count = mtm_output_row_number();
if (have_rows('mtm_home_topic_sections')) {
    ?>

	<div class="mtm-component mtm-home-topics">
		<section class="content--page content--home-topics">

			<?php 
    while (have_rows('mtm_home_topic_sections')) {
        the_row();
        // Loop through each item
        ?>

				<?php 
        $topic_tax_query = mtm_taxonomy_query_sub('home_topic', $display, 'DESC');
        $i = 1;
        ?>

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

					<div class="mtm-home-topic--single <?php 
            echo $mtm_news_feature_count;
            ?>
">
						<div class="mtm-home-topic--single-content">
					
						<?php 
            while ($topic_tax_query->have_posts()) {
</h2>

<?php 
}
if ('Pick From Taxonomy' == get_sub_field('mtm_list_archive_select')) {
    // Taxonomy Source
    ?>

	<div class="mtm-module--list">

		<?php 
    if (_get_sub_field('mtm_show_taxonomy_links')) {
        mtm_terms_from_taxonomy_links(get_sub_field('mtm_list_archive_taxonomy_links'));
        // output taxonomy
    }
    $list_query = mtm_taxonomy_query_sub('list');
    $taxonomy = mtm_acf_taxonomy_sub_property('list', 'taxonomy');
    $terms = mtm_acf_taxonomy_sub_property('list', 'slug');
    if ($list_query->have_posts()) {
        global $post;
        $org_post = $post;
        // save this in case we are inside a nested query/post object
        while ($list_query->have_posts()) {
            $list_query->the_post();
            mtm_get_template_part('mtm-content', 'list-view');
        }
        $post = $org_post;
        // reset to original query
    }
    if (_get_sub_field('mtm_show_view_all_link')) {
        ?>
<?php

// Featured Content Boxes Logic
while (have_rows('mtm_home_featured_content_boxes')) {
    the_row();
    // Loop through each item
    // Specific Content
    if ("Specific Content" == _get_sub_field('mtm_home_featured_type')) {
        $post_object = get_sub_field('mtm_home_featured_select_single');
        if ($post_object) {
            $post = $post_object;
            setup_postdata($post);
            mtm_get_template_part('mtm-content', 'home-feature-select');
        }
        // Show Latest Post
    } elseif ("Show Latest Post" == _get_sub_field('mtm_home_featured_type')) {
        $home_tax_query = mtm_taxonomy_query_sub('home_featured', 1);
        while ($home_tax_query->have_posts()) {
            $home_tax_query->the_post();
            mtm_get_template_part('mtm-content', 'home-feature-select');
        }
        // Manual Entry
    } else {
        mtm_get_template_part('mtm-content', 'home-feature-manual');
    }
    ?>

<?php 
}