<?php
/**
 * Template Name: Tournaments Template
 
 **/
get_header();

/**
 * DATA COLLECTION - START
 *
 */

/** Init variables **/
$limit_width = $limit_content_width = $the_content = $main_content = $layout = $bg_color = $sidebar_style = $sidebar_bg_color = $sidebar = $sidebar_size = $sidebar_sticky = $sidebar_padding = $sidebar_inner_padding = $sidebar_content = $title_content = $media_content = $navigation_content = $page_custom_width = $row_classes = $main_classes = $footer_content = $footer_classes = $content_after_body = '';
$with_builder = false;

$post_type = $post->post_type;

/** Get general datas **/
if (isset($metabox_data['_uncode_specific_style'][0]) && $metabox_data['_uncode_specific_style'][0] !== '') {
	$style = $metabox_data['_uncode_specific_style'][0];
	if (isset($metabox_data['_uncode_specific_bg_color'][0]) && $metabox_data['_uncode_specific_bg_color'][0] !== '') {
		$bg_color = $metabox_data['_uncode_specific_bg_color'][0];
	}
} else {
	$style = ot_get_option('_uncode_general_style');
	if (isset($metabox_data['_uncode_specific_bg_color'][0]) && $metabox_data['_uncode_specific_bg_color'][0] !== '') {
		$bg_color = $metabox_data['_uncode_specific_bg_color'][0];
	} else {
		$bg_color = ot_get_option('_uncode_general_bg_color');
	}
}
$bg_color = ($bg_color == '') ? ' style-'.$style.'-bg' : ' style-'.$bg_color.'-bg';


/** Get page width info **/
$boxed = ot_get_option('_uncode_boxed');

$page_content_full = (isset($metabox_data['_uncode_specific_layout_width'][0])) ? $metabox_data['_uncode_specific_layout_width'][0] : '';
if ($page_content_full === '') {

	/** Use generic page width **/
	$generic_content_full = ot_get_option('_uncode_' . $post_type . '_layout_width');
	if ($generic_content_full === '') {
		$main_content_full = ot_get_option('_uncode_body_full');
		if ($main_content_full === '' || $main_content_full === 'off') {
			$limit_content_width = ' limit-width';
		}
	} else {
		if ($generic_content_full === 'limit') {
			$generic_custom_width = ot_get_option('_uncode_' . $post_type . '_layout_width_custom');
			if ($generic_custom_width[1] === 'px') {
				if ( $generic_custom_width[0] == '' || ! is_numeric($generic_custom_width[0]) ) {
					$generic_custom_width[0] = 1200;
				}
				$generic_custom_width[0] = 12 * round(($generic_custom_width[0]) / 12);
			}
			if (is_array($generic_custom_width) && !empty($generic_custom_width)) {
				$page_custom_width = ' style="max-width: ' . implode("", $generic_custom_width) . '; margin: auto;"';
			}
		}
	}
} else {

	/** Override page width **/
	if ($page_content_full === 'limit') {
		$limit_content_width = ' limit-width';
		$page_custom_width = (isset($metabox_data['_uncode_specific_layout_width_custom'][0])) ? unserialize($metabox_data['_uncode_specific_layout_width_custom'][0]) : '';
		if (is_array($page_custom_width) && !empty($page_custom_width) && $page_custom_width[0] !== '') {
			if ($page_custom_width[1] === 'px') {
				$page_custom_width[0] = 12 * round(($page_custom_width[0]) / 12);
			}
			$page_custom_width = ' style="max-width: ' . implode("", $page_custom_width) . '; margin: auto;"';
		} else {
			$page_custom_width = '';
		}
	}
}

/** Collect header data **/
if (isset($metabox_data['_uncode_header_type'][0]) && $metabox_data['_uncode_header_type'][0] !== '') {
	$page_header_type = $metabox_data['_uncode_header_type'][0];
	if ($page_header_type !== 'none') {
		$meta_data = uncode_get_specific_header_data($metabox_data, $post_type, $featured_image);
		$metabox_data = $meta_data['meta'];
		$show_title = $meta_data['show_title'];
	}
} else {
	$page_header_type = ot_get_option('_uncode_' . $post_type . '_header');
	if ($page_header_type !== '' && $page_header_type !== 'none') {
		$metabox_data['_uncode_header_type'] = array($page_header_type);
		$meta_data = uncode_get_general_header_data($metabox_data, $post_type, $featured_image);
		$metabox_data = $meta_data['meta'];
		$show_title = $meta_data['show_title'];
	}
}

/** Get breadcrumb info **/
$generic_breadcrumb = ot_get_option('_uncode_' . $post_type . '_breadcrumb');
$page_breadcrumb = (isset($metabox_data['_uncode_specific_breadcrumb'][0])) ? $metabox_data['_uncode_specific_breadcrumb'][0] : '';
if ($page_breadcrumb === '') {
	$breadcrumb_align = ot_get_option('_uncode_' . $post_type . '_breadcrumb_align');
	$show_breadcrumb = ($generic_breadcrumb === 'off') ? false : true;
} else {
	$breadcrumb_align = (isset($metabox_data['_uncode_specific_breadcrumb_align'][0])) ? $metabox_data['_uncode_specific_breadcrumb_align'][0] : '';
	$show_breadcrumb = ($page_breadcrumb === 'off') ? false : true;
}

/** Get title info **/
$generic_show_title = ot_get_option('_uncode_' . $post_type . '_title');
$page_show_title = (isset($metabox_data['_uncode_specific_title'][0])) ? $metabox_data['_uncode_specific_title'][0] : '';
if ($page_show_title === '') {
	$show_title = ($generic_show_title === 'off') ? false : true;
} else {
	$show_title = ($page_show_title === 'off') ? false : true;
}

/**
 * DATA COLLECTION - END
 *
 */

while (have_posts()):
	the_post();

	/** Build header **/
	if ($page_header_type !== '' && $page_header_type !== 'none') {
		$page_header = new unheader($metabox_data, $post->post_title, $post->post_excerpt);

		$header_html = $page_header->html;
		if ($header_html !== '') {
			echo '<div id="page-header">';
			echo uncode_remove_p_tag( $page_header->html );
			echo '</div>';
		}

		if (!empty($page_header->poster_id) && $page_header->poster_id !== false && $media !== '') {
			$media = $page_header->poster_id;
		}
	}
	echo '<script type="text/javascript">UNCODE.initHeader();</script>';
	/** Build breadcrumb **/

	if ($show_breadcrumb && !is_front_page() && !is_home()) {
		if ($breadcrumb_align === '') {
			$breadcrumb_align = 'right';
		}
		$breadcrumb_align = ' text-' . $breadcrumb_align;

		$content_breadcrumb = uncode_breadcrumbs();
		$breadcrumb_title = '<div class="breadcrumb-title h5 text-bold">' . get_the_title() . '</div>';
		echo uncode_get_row_template($breadcrumb_title . $content_breadcrumb , '', ($page_custom_width !== '' ? ' limit-width' : $limit_content_width), $style, ' row-breadcrumb row-breadcrumb-' . $style . $breadcrumb_align, 'half', true, 'half');
	}
	
	/** Build title **/

	if ($show_title) {
		$title_content .= apply_filters( 'uncode_before_body_title', '' );
		$title_content .= '<div class="post-title-wrapper"><h1 class="post-title">' . get_the_title() . '</h1>';
		// $title_content .= uncode_post_info();
		$title_content .= '</div>';
		$title_content .= apply_filters( 'uncode_after_body_title', '' );
	}


	

	/** Build post footer **/

	$page_show_share = (isset($metabox_data['_uncode_specific_share'][0])) ? $metabox_data['_uncode_specific_share'][0] : '';
	if ($page_show_share === '') {
		$generic_show_share = ot_get_option('_uncode_' . $post_type . '_share');
		$show_share = ($generic_show_share === 'off') ? false : true;
	} else {
		$show_share = ($page_show_share === 'off') ? false : true;
	}

	if ($show_share) {
		$footer_content = '<div class="post-share">
	          						<div class="detail-container margin-auto">
													<div class="share-button share-buttons share-inline only-icon"></div>
												</div>
											</div>';
	}

	

	/** Build and display navigation html **/
	$navigation_option = ot_get_option('_uncode_' . $post_type . '_navigation_activate');
	if ( $navigation_option !== 'off' && false ) {
		$generic_index = true;
		if (isset($metabox_data['_uncode_specific_navigation_index'][0]) && $metabox_data['_uncode_specific_navigation_index'][0] !== '') {
			$navigation_index = $metabox_data['_uncode_specific_navigation_index'][0];
			$generic_index = false;
		} else {
			$navigation_index = ot_get_option('_uncode_' . $post_type . '_navigation_index');
		}
		if ($navigation_index !== '') {
			$navigation_index_label = ot_get_option('_uncode_' . $post_type . '_navigation_index_label');
			$navigation_index_link = get_permalink($navigation_index);
			$navigation_index_btn = '<a class="btn btn-link text-default-color" href="' . esc_url($navigation_index_link) . '">' . ($navigation_index_label === '' ? get_the_title($navigation_index) : esc_html($navigation_index_label)) . '</a>';
		} else {
			$navigation_index_btn = '';
		}
		$navigation_nextprev_title = ot_get_option('_uncode_' . $post_type . '_navigation_nextprev_title');
		$navigation = uncode_post_navigation($navigation_index_btn, $navigation_nextprev_title, $navigation_index, $generic_index);
		if ($page_custom_width !== '') {
			$limit_content_width = ' limit-width';
		}
		if (!empty($navigation) && $navigation !== '') {
			$navigation_content = uncode_get_row_template($navigation, '', $limit_content_width, $style, ' row-navigation row-navigation-' . $style, true, true, true);
		}
	}
	
	/** Build post footer **/

	$page_show_share = (isset($metabox_data['_uncode_specific_share'][0])) ? $metabox_data['_uncode_specific_share'][0] : '';
	if ($page_show_share === '') {
		$generic_show_share = ot_get_option('_uncode_' . $post_type . '_share');
		$show_share = ($generic_show_share === 'off') ? false : true;
	} else {
		$show_share = ($page_show_share === 'off') ? false : true;
	}
	
// get the content
ob_start();
?>
<div class="inner">
		<!-- Begin main content -->
		<div class="inner_wrapper">
			<div class="sidebar_content full_width blog_f">
				<?php
	
	?>
<!-- Begin each blog post -->
<div id="post-<?php  the_ID(); ?>" <?php  post_class(); ?>>
	<div class="post_wrapper">
		<div class="post_content_wrapper">
			<div class="custom_fields clear clearfix">				
			<?php 
 	
			 $values= get_post_meta( get_the_ID(),'lake');
			
			 $map_val = get_field('google_map',$values[0]);
			 
			
 
			 if( !empty($map_val) ):
			?>
			<?php /*
<div class="acf-map">
	<div class="marker" data-lat="<?php echo $map_val['lat']; ?>" data-lng="<?php echo $map_val['lng']; ?>"></div>
</div>
*/ ?>
<div class="acf-map acf-map-navionics" data-lat="<?php  echo $map_val['lat']; ?>" data-lng="<?php  echo $map_val['lng']; ?>">
</div>
<?php endif; ?> 

 
<?php 
	$from_date= get_post_meta(get_the_ID(),'from_date',true);
	$to_date= get_post_meta(get_the_ID(),'to_date',true);
	$lake_obj = get_field('lake');
	$trail =get_field('trail');
	$landings =get_field('landing');
	$contact_persons_name =get_field('contact_persons_name');
	$phone = get_field('phone');
	$sponsors = get_field('sponsors');
	$email = get_field('email_address');
	$web_address = get_field('web_address');
	$description = get_field('large_description');
	$tournamentsID = get_the_ID();
	$trailID = 0;
?> 

 <div class="extra_fields">
 <?php if(($lake_obj)){?>
 <?php $values= get_post_meta( $tournamentsID,'lake');
			if(isset($values[0]) &&  is_numeric($values[0]) && $values[0] > 0) {
				$trailpost = new WP_Query(
					array( 
						'p' => $values[0],
						'post_type'=> 'lakes'
					)
				);
				$lakeName = "";
				$Lake_get_the_ID = $values[0];
				if ( $trailpost->have_posts() ) {
					echo '<div class="extra_field"><strong>Lake:&nbsp; </strong> ';
					while ( $trailpost->have_posts() ) {
						$trailpost->the_post();
						$lakeName= get_the_title();
						echo  '<a href="'.get_permalink().'" >'.titlechange(get_the_title()).'</a>';
					}
					echo '</div>';
					/* Restore original Post Data */
					wp_reset_postdata();
				}
			}
			?><?php }?> <?php if(($landings)){?>
			<?php 
			
			$landingvalues= get_post_meta( $tournamentsID,'landing');
			if(isset($landingvalues[0]) &&  is_numeric($landingvalues[0]) && $landingvalues[0] > 0) {
				$landingspost = new WP_Query(array( 'p' => $landingvalues[0],'post_type'=> 'landings' ));
				if ( $landingspost->have_posts() ) {
					echo '<div class="extra_field"><strong>Landings:&nbsp; </strong> ';
					while ( $landingspost->have_posts() ) {
						$landingspost->the_post();
						echo  '<a href="'.get_permalink().'" >'.titlechange(get_the_title()).'</a>';
					}
					echo '</div>';
					/* Restore original Post Data */
					wp_reset_postdata();
				}
			}
			?>
            <?php }?> 
			<?php if(($trail)){?>
			<?php  
			//print_r(get_post_meta( get_the_ID()));
			$trailvalues= get_post_meta( $tournamentsID,'trail');
			if(isset($trailvalues[0]) &&  is_numeric($trailvalues[0]) && $trailvalues[0] > 0) {
				$trailpost = new WP_Query(array( 'p' => $trailvalues[0],
												'post_type'=> 'trails' ));
				if ( $trailpost->have_posts() ) {
					echo '<div class="extra_field"><strong>Trail:&nbsp; </strong> ';
					while ( $trailpost->have_posts() ) {
						$trailpost->the_post();
						$trailID = get_the_ID();
						echo  '<a href="'.get_permalink().'" >'.titlechange(get_the_title()).'</a>';
					}
					echo '</div>';
					/* Restore original Post Data */
					wp_reset_postdata();
				}
			}
			
			?>
            <?php }?> 
			<?php if(!empty($from_date) || !empty($to_date)){?><div class="extra_field"><strong>Date:&nbsp; </strong><span style="text-transform:none;">
<?php echo date_i18n('m/d/Y',strtotime($from_date)); ?> to 
<?php echo date_i18n('m/d/Y',strtotime($to_date)); ?></div> <?php } if(!empty($phone)){?><div class="extra_field"><strong>Phone:&nbsp; </strong> <?php echo $phone ;?></div> <?php } if(!empty($contact_persons_name)){?><div class="extra_field"><strong>Contact:&nbsp; </strong>  <?php echo $contact_persons_name ;?></div> <?php  }  if(!empty($email)){?><div class="extra_field"><strong>Email: &nbsp;</strong><a href="mailto:<?php echo $email ;?>"> <?php echo $email ;?></a></div> <?php  } if(!empty($sponsors)){?> <div class="extra_field"><strong>Sponsors:&nbsp; </strong><?php echo $sponsors ;?></div><?php } if(!empty($web_address)){?> <div class="extra_field"><strong>Website: &nbsp;</strong><a href="http://<?php echo $web_address ;?>" target="_blank"> <?php echo $web_address ;?></a></div><?php }?> 
 
	</div>
</div>
<div class="clear clearfix"></div>
 
<?php
	$location = '';
	if ( !empty( $lake_obj ) ) {
	
		$state= strtoupper( get_term( get_field('state', $lake_obj ) )->slug );
	
		$location = get_the_title( $lake_obj ).', '. $state;
	}
	
?>

<div class="ics_wrap clear clearfix">
	<a href="#" class="btn button add_to_call"
		data-subject="<?php echo get_the_title(); ?>"
		data-location="<?php echo $location; ?>"
		data-begin="<?php echo $from_date; ?>"
		data-end="<?php echo $to_date; ?>"
		data-description="<?php echo esc_js( $description ); ?>"
	><i class="fa fa-calendar" aria-hidden="true"></i> Add to Calendar</a>
</div>
 
 <?php

 if ( $show_share ) {
	echo '<div class="post-share">
		<div class="detail-container margin-auto">
						<div class="share-button share-buttons share-inline only-icon"></div>
					</div>
				</div>';
}
?>
<?php if(!empty($description)){ ?>
 			<div class="description_txt">
            <?php echo  $description; ?>
            </div>
<?php }?> 

<?php
			 $trail_post = get_posts( array( 'post_type'		=>	'tournaments',
										'meta_key'		=> 'trail',
										'meta_value'	=> $trailID,
										'orderby' => 'post_date',
										'order' => 'ASC'
										)
									   );?>
	<?php 
	if( $trail_post ): ?>
	<div class="dtable" style="margin-bottom:30px;">
    
    <div class="dheading">
        <div class="dcell" style="text-align:left;">
            <p>Tournaments</p>
        </div>
        <div class="dcell" style="text-align:left;">
            <p>Trail</p>
        </div>
        <div class="dcell" style="text-align:left;">
            <p>LAKE/LANDING</p>
        </div>
        
    </div>
    <?php
	foreach( $trail_post as $trailposts ): 
	setup_postdata( $trailposts );
	//print_r($trailposts);
	$from_date= get_post_meta($trailposts->ID,'from_date',true);
	$to_date= get_post_meta($trailposts->ID,'to_date',true);
	?>

    <div class="drow">
        <div class="dcell text_title">
            <p ><a href="<?php echo get_permalink($trailposts->ID);?>"><?php echo titlechange($trailposts->post_title);?></a>
            <br /><span class="post_info_date" style="text-transform:none;"><?php echo date_i18n('m/d/Y',strtotime($from_date)); ?> to 
			<?php echo date_i18n('m/d/Y',strtotime($to_date)); ?> </span>
                    </p>
        </div>
        <div class="dcell">
            <?php  
			//print_r(get_post_meta( get_the_ID()));
			$values= get_post_meta( $trailposts->ID,'trail');
			if(isset($values[0]) && is_numeric($values[0]) && $values[0] > 0) {
			$trailpost = new WP_Query(array( 'p' => $values[0],
											'post_type'=> 'trails' ));
			if ( $trailpost->have_posts() ) {
				
				while ( $trailpost->have_posts() ) {
					$trailpost->the_post();
					echo  '<a href="'.get_permalink().'" >'.titlechange(get_the_title()).'</a><br>';
					echo "<span>".get_field('division')."</span>";
				}
				
				/* Restore original Post Data */
				wp_reset_postdata();
			}
			}?>
        </div>
        <div class="dcell">
            <?php  
			$lakesvalues= get_post_meta( $trailposts->ID,'lake');
			$landingvalues= get_post_meta( $trailposts->ID,'landing');
			//print_r($lakesvalues);
			if(isset($lakesvalues[0]) && is_numeric($lakesvalues[0]) && $lakesvalues[0] > 0) {
			$lakespost = new WP_Query(array( 'p' => $lakesvalues[0],
											'post_type'=> 'lakes' ));
			if ( $lakespost->have_posts() ) {
				
				while ( $lakespost->have_posts() ) {
					$lakespost->the_post();
					echo  '<a href="'.get_permalink().'" >'.titlechange(get_the_title()).'</a>';
				}
				/* Restore original Post Data */
				wp_reset_postdata();
			}
			}
			
			//print_r($lakesvalues);
			if(isset($landingvalues[0]) && is_numeric($landingvalues[0]) && $landingvalues[0] > 0) {
			$landingpost = new WP_Query(array( 'p' => $landingvalues[0],
											'post_type'=> 'landings' ));
			if ( $landingpost->have_posts() ) {
				
				while ( $landingpost->have_posts() ) {
					$landingpost->the_post();
					echo  '<br><a href="'.get_permalink().'" ><span style="text-transform:uppercase;" class="post_info_date">'.titlechange(get_the_title()).'</span></a>';
				}
				
				/* Restore original Post Data */
				wp_reset_postdata();
			}
			}?>
        </div>
        
    </div>
    <?php endforeach;  ?>
</div>
<?php endif; ?>
			
			
			
			<div class="single-lakes">
			<div class="lakes_container" style="margin-bottom:30px;">
		  
		   <?php 
		   
			 $lakes_post = get_posts( array( 'post_type'		=>	'listings',
										'showposts'   => -1,
										'meta_key'		=> 'lake',
										'meta_value'	=> $Lake_get_the_ID
										)
									   );//print_r($lakes_post);
			if( $lakes_post ):
				$total_posts = count( $lakes_post );
			?>
				<div class="post_header">
					<div class="post_header_title">
					
						<h1><?php echo esc_html_e( 'Lake Guide', 'grandnews' ); ?></h1>
						<div class="post_info_type">
						</div>
					
					</div>
				</div>
				
				<hr class="post_divider"/><br class="clear"/>

				<div class="lake-listings-wrap">
					<?php 
					foreach( $lakes_post as $i => $lakesposts ): 
						setup_postdata( $lakesposts );
						$address= get_post_meta($lakesposts->ID,'google_map',true);
						$phone= get_post_meta($lakesposts->ID,'phone',true);
						$guide_categories= get_post_meta($lakesposts->ID,'guide_categories',true);

						//print_r($logo);
						?>
						<div class="lake-listing-wrap <?php echo 0 == ( $i + 1 ) % 3 ? ' last' : ''; ?>">
							<div class="lake_listing clear">
								<div class="text-left-remove">
									<h6><a href="<?php echo get_permalink($lakesposts->ID );?>"><?php  echo strtoupper(titlechange($lakesposts->post_title));?></a></h6>									
									<?php if($address){?><div class="sub-text"><?php echo $address['address'];?></div><?php }?>
									<?php if(!empty($lakeName)) { echo '<div class="guidelakename">'.$lakeName.'</div>'; } ?>
									<div class="guide-category"><span><?php  
										//echo implode(', ', $guide_categories);
										if(isset($guide_categories[0])) {
											echo $guide_categories[0];
										}
										
										?></span></div>
								</div>
							</div><!-- /.lake_listing -->
						</div><!-- /.lake-listing-wrap -->
				<?php if ( 0 == ( $i + 1 ) % 3 && ( $i + 1 ) != $total_posts ) : ?>
			</div><!-- /.lake-listings-wrap -->
			<div class="lake-listings-wrap">
				<?php endif; ?>
					<?php 
					endforeach; ?>
				</div><!-- /.lake-listings-wrap -->
			<?php endif; ?>
			</div>
			</div>
			
			
				<?php
				//Get related posts
			    $tg_blog_display_related = true;
			    
			    if($tg_blog_display_related)
			    {
			?>
			
			<?php
			//for use in the loop, list 9 post titles related to post's tags on current post
				   
			
			  	$args=array(
					  'post_type'		=>	'post',
			      	  'post__not_in' => array(get_the_ID()),
					  'meta_value'	=> get_the_ID(),'meta_key'		=> 'tournament',
					  'showposts' => 12,
			      	  'orderby' => 'post_date',
			      	  'order' => 'DESC'
			  	 );
				// print_r(	$args);exit;
			  	$my_query = new WP_Query($args);
			  	$i_post = 1;
			  	
if( $my_query->have_posts() ) {
			?>
			 	<h1><?php  echo esc_html_e( 'Related Posts', 'grandnews' ); ?></h1>
				<hr class="post_divider"/><br class="clear"/>
				<div class="post_related">
				<div class="isotope-system">
					<div class="isotope-wrapper single-gutter">
						<div class="isotope-container isotope-layout style-masonry" data-type="masonry" data-layout="masonry" data-lg="800" >
				<?php
			while ($my_query->have_posts()) :
			$my_query->the_post();
			// $opinion= get_post_meta(the_ID());
			$opinion_piece= strtolower(trim(get_field('opinion_piece',get_the_ID())));
			//echo $opinion_piece;
			$last_class = '';
			
			if($i_post%3==0)   {
				$last_class = 'last';
			}

			$image_thumb = '';
			
			if(has_post_thumbnail(get_the_ID(), 'large')){
				$image_id = get_post_thumbnail_id(get_the_ID());
				$image_thumb = wp_get_attachment_image_src($image_id, 'large', true);
			}

			?>
		
					<div id="post-<?php  the_ID(); ?>" class="tmb tmb-iso-w3 tmb-iso-h4 tmb-round tmb-light tmb-text-showed tmb-content-center tmb-image-anim tmb-shadowed tmb-shadowed-sm tmb-entry-title-uppercase post-<?php  the_ID(); ?> status-publish hentry tmb-content-under tmb-iso <?php  echo esc_attr($last_class); ?>">
						<div class="t-inside style-light-bg">
							<div class="t-entry-text">
					   <!-- Begin each blog post -->
						
								<?php
			//Get post featured content
			
			if(!empty($image_thumb)){
				$small_image_url = wp_get_attachment_image_src($image_id, 'grandnews_blog_thumb', true);
				?>
								
								
									<div class="t-entry-visual" style="height: 252px;">
										<div class="t-entry-visual-tc">
											<div class="t-entry-visual-cont">
												<div class="dummy" style="padding-top: 66.7%;"></div>
												<a tabindex="-1" href="<?php  the_permalink(); ?>" class="pushed" target="_self" data-lb-index="2">
													<div class="t-entry-visual-overlay">
														<div class="t-entry-visual-overlay-in style-color-wayh-bg" style="opacity: 0.5;"></div>
													</div>
													<div class="t-overlay-wrap">
														<div class="t-overlay-inner">
															<div class="t-overlay-content">
																<div class="t-overlay-text half-block-padding">
																	<div class="t-entry t-single-line"></div>
																</div>
															</div>
														</div>
													</div>
												  <img src="<?php  echo esc_url($small_image_url[0]); ?>" alt="" class="related_img" /></a>
											</div>
										</div>
									</div>
								<?php
			} ?>
			
								<div class="t-entry-text">
									<div class="t-entry-text-tc half-block-padding">
										<div class="t-entry">
											<p class="t-entry-meta"><span class="t-entry-date"><?php  echo date_i18n(get_option( 'date_format' ), get_the_time('U')); ?></span></p>
											<h3 class="t-entry-title h5"><a href="<?php  the_permalink(); ?>" title="<?php  the_title(); ?>" target="_self"><?php  echo titlechange(get_the_title()); ?></a></h3></div>
									</div>
								</div>						
						
						<!-- End each blog post -->
						</div>
					</div>
				</div>

				 <?php
			$i_post++;
			endwhile;
			wp_reset_postdata();
			?>
				</div>
				</div>
			</div>
		</div>
            <?php
 }
			//}
			?>
			
			<?php
			    } //end if show related
			?>

			
			
		</div>
	</div>
</div>
<!-- End each blog post -->

</div>
</div>
</div>
<?php
	
$content = ob_get_clean();



	/** Display post html **/
	echo 	'<article id="post-'. get_the_ID().'" class="'.implode(' ', get_post_class('page-body' . $bg_color)) .'">
          <div class="post-wrapper">
          	<div class="post-body">
				<div class="row-container">
					<div class="row row-parent style-light limit-width double-top-padding double-bottom-padding">
			'. $title_content .'
			'. $content .'
					</div>
				</div>
			</div>
		' .
          	$navigation_content . '
          </div>
        </article>';

endwhile;
// end of the loop.

get_footer(); ?>
