<?php

global 
$relatedargs, 
$relatedcatargs, 
$post,
$grid_size;

ag_get_related_post_args( $post->ID ); // get info for related posts

// Query Posts by tag
$my_query = new WP_Query( $relatedargs );

// If no related posts by tag, query by category
if ( ! $my_query->have_posts() ) {
  	wp_reset_query(); 
	$my_query = new WP_Query( $relatedcatargs );
}
//If there are posts
if( $my_query->have_posts() ) { 
	$grid_size = "related"; ?>

	<!-- Related Posts -->
	<div class="related-posts">
		<div class="related-inner">
			<div class="section-title">
				<p><span><?php _e('You Might Also Like', 'themewich'); ?></span></p>
			</div>

			<?php while ($my_query->have_posts()) : $my_query->the_post(); 
				get_template_part(TW_TEMPLATES_DIR .'/template-grid');
			endwhile; //End Loop  ?>
			  
	  		<div class="clear"></div>
	  	</div>
	</div>
<?php } wp_reset_query(); // end if there are posts and reset the query ?>