<?php
/**
 * The template for displaying the grid section with sidebar.
 *
 * @package WordPress
 * @subpackage Edition
 * @since Edition 1.0
 */
global
$tw_order_class, 	// section order
$tw_section, 		// section object
$paged_section;		// section pagination

$tw_section 	= themewich_section_object(); 		// section post options
$section_post 	= $post; // Store Section Post

// Set post classes
$tw_section->post_classes  = array(
	'no-top-margin',
	'regular-posts',
	'section',
	$tw_order_class,
	$tw_section->title_class
); ?>

<div <?php post_class($tw_section->post_classes); ?>>
	<?php themewich_section_edit(); // edit button ?>

	<div class="container">
		<div class="rightside">
			<div class="rightcontent regulargrid">
				<?php get_template_part( TW_SECTIONS_DIR .'/section-title'); 	// Section title  ?>
				<div class="loading"></div>
				<div class="regularwrapper" id="section-<?php the_ID(); ?>">
					<div class="homeposts">
						<div class="isotopecontainer" data-value="2">
							<?php
								// for pagination
								global $wp_query;
								$paged_section = isset( $_GET['paged_section'] ) ? (int) $_GET['paged_section'] : 1;

								// Additional query arguments
								$args = array(
									'ignore_sticky_posts'   => 1,   					// Ignore Sticky Posts
									'post_type'             => array( 'post' ), 		// Get posts
									'paged'                 => $paged_section,  				// Add pagination
								);

								// Filter the latest posts by type chosen
								$args = themewich_post_args($args);

								wp_reset_query(); 					// Reset query
								$wp_query = new WP_Query($args); 	// Query the posts

								// Start the loop
								while ($wp_query->have_posts()) : $wp_query->the_post();
							?>

							<?php get_template_part(TW_TEMPLATES_DIR . '/regular-post'); ?>

							<?php
								endwhile; 			// End Loop
							?>
							<div class="clear"></div>
						</div>

						<?php
							if ($tw_section->section_pagination != 'off') :
								themewich_pagination();
							endif; // end if pagination
						?>
					</div><!--.homeposts-->

				</div><!--.regularwrapper-->

			</div><!--.rightcontent-->
			<div class="clear"></div>
		</div><!--.rightside-->

		<div class="sidebar">
			<div class="sidebarcontent">
				<?php
					$post_id    = $section_post->ID; // Get correct post ID
					if ( ! acf_Widget::dynamic_widgets( 'Posts Section Sidebar', $post_id ) ) {
						dynamic_sidebar( 'Posts Sidebar' ); //fallback to default sidebar if nothing is set
					}
				?>
            </div>
        </div>

    </div><!--.container-->
</div><!--.homesection-->