<?php while ( have_posts() ) : the_post(); ?>
	<!-- listing-detail
		================================================== -->
	<section class="listing-detail">
		<?php 
		    $gallery = get_post_meta(get_the_ID(), '_triptip_gallery', true);
		?>
		<?php if(is_array($gallery) and $gallery!=''){ ?>
			<div class="listing-detail__gal">
				<ul class="listing-detail__fullwidth-gal">
					<?php $j=0; foreach($gallery as $id => $url) { ?>
						<?php $img = wp_get_attachment_image_src($id, ''); ?>
						<li>
							<a href="<?php echo esc_url($img[0]); ?>" class="zoom">
								<img src="<?php echo esc_url($img[0]); ?>" alt="<?php the_title_attribute(); ?>" />
							</a>
						</li>
				
					<?php } ?>
				</ul>
			</div>
		<?php } ?>
		<div class="container">
			<div class="listing-detail__title-box">
				<div class="row">
					<div class="col-md-6">
						<?php if( function_exists('triptip_comment_rating_get_average_ratings') ){ triptip_comment_rating_get_average_ratings(get_the_ID()); }  ?>
						<h1 class="listing-detail__title listing-detail__title-black">
							<?php the_title(); ?>
						</h1>
						<?php 
							$address = get_post_meta(get_the_ID(), '_triptip_address', true);
							if($address!=''){ 
						?>
							<p class="listing-detail__address"><i class="fa fa-map-marker"></i> <?php echo esc_html($address); ?></p>
						<?php } ?>
					</div>
					<div class="col-md-6">
						<div class="listing-detail__buttons">
							<a class="btn-default btn-default-red navigate-btn" href="#leave-review">
								<i class="la la-pencil" aria-hidden="true"></i>
								<?php esc_html_e('Write a Review','triptip'); ?>
							</a>
							<?php if( function_exists('get_simple_likes_button') ) echo get_simple_likes_button(get_the_ID());?>

							<?php echo do_shortcode('[share_button style="btn-default-red" text="'.esc_html__('Share','triptip').'"]'); ?>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="listing-detail__content">
			<div class="container">
				<div class="row">
					<div class="col-lg-8">
						<div class="listing-detail__content-box">
									<!-- overview box -->
							<div class="listing-detail__overview" id="overview-box">

								<h2 class="heading2 listing-detail__content-title"><?php esc_html_e('Overview','triptip'); ?></h2>

								<div class="row">
									<div class="col-md-6">
										<?php the_content(); ?>
									</div>
									<div class="col-md-6">
										<?php 
											$latitude = get_post_meta(get_the_ID(), '_triptip_latitude', true);
											$longitude = get_post_meta(get_the_ID(), '_triptip_longitude', true);
											$icon = get_post_meta(get_the_ID(), '_triptip_mapicon', true);
										?>
										<?php if($longitude!='' and $latitude!=''){ ?>
											
											<div id="mapSingle" data-latitude="<?php echo esc_attr($latitude); ?>" data-longitude="<?php echo esc_attr($longitude); ?>" data-map-icon="<?php echo esc_attr($icon); ?>"></div>
										<?php } ?>
									</div>
								</div>
							</div>

						</div>
					</div>
					<div class="col-lg-4">
						<div class="sidebar">
							<?php $brand = get_post_meta(get_the_ID(), '_triptip_brand', true); ?>
							<?php if($brand!=''){ ?>
								<div class="sidebar__map-widget">
									<h2 class="heading2 sidebar__widget-title">
										<?php esc_html_e('Logo Brand', 'triptip'); ?>
									</h2>
									<img class="logo-brand" src="<?php echo esc_url($brand); ?>" alt="<?php the_title_attribute();?>">
								</div>
							<?php } ?>
							
							<div class="sidebar__widget sidebar__widget-listing-details">
								<h2 class="heading2 sidebar__widget-title">
									<?php esc_html_e('Details', 'triptip'); ?>
								</h2>
								<ul class="sidebar__listing-list">
									<li>
										<?php 
										if($address!=''){ ?>
											<i class="la la-map-marker"></i>
											<?php echo esc_html($address); ?>
										<?php } ?>
									</li>
									<?php $phone = get_post_meta(get_the_ID(), '_triptip_phone', true); ?>
									<?php if($phone!=''){ ?>
										<li>
											<i class="la la-mobile-phone"></i>
											<a href="tel:<?php echo esc_attr($phone); ?>"><?php echo esc_html($phone); ?></a>
										</li>
									<?php } ?>
									<?php $email = get_post_meta(get_the_ID(), '_triptip_email', true); ?>
									<?php if($email!=''){ ?>
										<li>
											<i class="la la-envelope-o"></i>
											<a href="mailto:<?php echo esc_attr($email); ?>"><?php echo esc_html($email); ?></a>
										</li>
									<?php } ?>
									<?php $website = get_post_meta(get_the_ID(), '_triptip_website', true); ?>
									<?php if($website!=''){ ?>
										<li>
											<i class="la la-link"></i>
											<a href="<?php echo esc_url($website); ?>" target="_blank"><?php echo esc_html($website); ?></a>
										</li>
									<?php } ?>
									<?php $custom_meta = get_post_meta( get_the_ID(), 'custom_meta', true ); ?>
									<?php if($custom_meta!=null){ ?>
										<?php 
											$i=1; foreach ( (array) $custom_meta as $key => $entry ) { ?>
											<li>
												<?php if($entry['icon']!=''){ ?>
													<i class="<?php echo esc_attr($entry['icon']); ?>"></i>
												<?php } ?>
												<?php echo esc_html($entry['title']); ?>: <?php echo esc_html($entry['value']); ?>
											</li>
										<?php $i++; }?>
									<?php } ?>
								</ul>
								<?php if( function_exists('qkl_business_hours') ){ qkl_business_hours(); } ?>
							</div>

						</div>
					</div>
				</div>
			</div>
		</div>
		
	</section>
	<!-- End listing-detail -->
	<?php
	  $item_cats = get_the_terms( $wp_query->get_queried_object_id(), 'listing-tag');
	  $portfolio_cats = array();
	  foreach((array)$item_cats as $item_cat){
	    $portfolio_cats[] = $item_cat->slug;
	  }
	  
	  $id = $wp_query->get_queried_object_id();
	  $query = new WP_Query(array(
	  							'post__not_in' => array( $id ),
	  							'post_type'=>'listing',
	  							'posts_per_page' => 9,
	  							'tax_query' => array(array(
	  									'taxonomy' => 'listing-tag',
										'field' => 'slug',
										'terms' => $portfolio_cats))));
	?>
	<?php if($query->found_posts > 0){ ?>
		<!-- trending-places-block
			================================================== -->
		<section class="trending-places trending-places-listing">
			<div class="container">
				<h2 class="heading2 trending-places-listing__title"><?php esc_html_e('Best Moderately Priced', 'triptip'); ?></h2>
				<div class="trending-places__box owl-wrapper">
					<div class="owl-carousel" data-num="5">
					<?php 
				      if($query->have_posts()) :
				             $i=1; while($query->have_posts()) : $query->the_post(); 
				    ?>
						<div class="item">

							<!-- place-post module -->
							<div class="place-post">
								<div class="place-post__gal-box">
									<?php the_post_thumbnail('', ['class' => 'place-post__image']); ?>
									<?php if( function_exists('triptip_post__ratings_get_average') ) triptip_post__ratings_get_average(get_the_ID()); ?>
									<?php if( function_exists('get_simple_likes_button') ) echo get_simple_likes_button(get_the_ID());?>
								</div>
								<div class="place-post__content">
									<?php if( function_exists('qkl_working_status') ){ qkl_working_status(); } ?>
									<h2 class="heading2 place-post__title">
										<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
									</h2>
									<p class="place-post__description">
										<?php  if( function_exists('qkl_listing_category') ){ qkl_listing_category(get_the_ID()); } ?>
										<?php if( function_exists('triptip_price_range') ){  triptip_price_range(); }  ?>
										<span class="place-post__description-review">
											<i class="fa fa-comment-o" aria-hidden="true"></i>
											<?php comments_number( esc_html__('0 Reviews','triptip'), esc_html__('1 Review','triptip'), esc_html__('% Reviews','triptip') ); ?>
										</span>
									</p>
									<?php if(get_post_meta(get_the_ID(), '_triptip_address',true)!=''){ ?>
									<p class="place-post__address">
										<i class="fa fa-map-marker" aria-hidden="true"></i>
										<?php echo esc_html(get_post_meta(get_the_ID(), '_triptip_address',true)) ?>
									</p>
									<?php } ?>
								</div>
							</div>
							<!-- end place-post module -->

						</div>
					
						<?php endwhile; endif; wp_reset_postdata(); ?>
						
					</div>
				</div>
			</div>
		</section>
		<!-- End trending-places-block -->
	<?php } ?>
	<!-- listing-detail
		================================================== -->
	<section class="listing-detail">

		<div class="listing-detail__content">
			<div class="container">
				<div class="row">
					<div class="col-lg-8">
						<div class="listing-detail__content-box">

							<?php if ( comments_open() || get_comments_number() ) {  ?>
				                <?php comments_template(); ?>   
				            <?php } ?>


						</div>
					</div>
					<div class="col-lg-4">
						<div class="sidebar">

							
							<div class="sidebar__widget sidebar__widget-tags">
								<h2 class="heading2 sidebar__widget-title">
									<?php esc_html_e('Listing Tags', 'triptip'); ?>
								</h2>
								<?php 
									$tags = wp_get_post_terms( get_the_ID(), 'listing-tag' ); 
								?>
								<?php if($tags){ ?>
									<ul class="sidebar__tags-list">
										<?php foreach($tags as $tag){ ?>
											<li><a href="<?php echo get_term_link($tag->slug, 'listing-tag'); ?>"><?php echo esc_html($tag->name); ?></a></li>
										<?php } ?>
									</ul>
								<?php } ?>
							</div>
							<?php if(qkl_get_setting('author_block')!='off'){ ?>
								<div class="sidebar__widget sidebar__widget-author">
									<h2 class="heading2 sidebar__widget-title">
										<?php esc_html_e('Author', 'triptip'); ?>
									</h2>
									
									<!-- Author-wrapper module -->
									<div class="author-wrapper">
										<div class="author-wrapper__profile">
											<div class="row">
												<div class="col-7">
													<div class="author-wrapper__content">
														<a class="author-wrapper__image" href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>">
														<?php if(get_user_meta(get_the_author_meta('ID'), '_triptip_avatar' ,true)!=''){ ?>
												            <?php $image = get_user_meta(get_the_author_meta('ID'), '_triptip_avatar' ,true); ?>
												            <img src="<?php echo esc_url($image); ?>" />
												        <?php }else{ ?>
												          <?php echo get_avatar(get_the_author_meta('user_email'),$size='100',$default='https://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=120' ); ?>
												        <?php } ?>
														</a>
														<h3 class="heading3 author-wrapper__title">
															<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>"><?php echo esc_html(get_the_author_meta('display_name'));?></a>
															<?php if(get_user_meta(get_the_author_meta('ID'), '_triptip_user_address' ,true)!=''){ ?>
																<span class="author-wrapper__location">
																	<?php echo get_user_meta(get_the_author_meta('ID'), '_triptip_user_address' ,true); ?>
																</span>
															<?php } ?>
														</h3>
													</div>
												</div>
												
											</div>
										</div>
										<ul class="author-wrapper__list">
											<li>
												<span><?php echo count_user_posts( get_the_author_meta( 'ID' ) , 'listing' ); ?></span>
												<?php esc_html_e('Listing', 'triptip'); ?>
											</li>
											
											<li>
												<span><?php echo count_user_posts( get_the_author_meta( 'ID' ) ); ?></span>
												<?php esc_html_e('Posts', 'triptip'); ?>
											</li>
											<?php  if( function_exists('qkl_comment_count') ){ ?>
												<li>
													<span><?php  qkl_comment_count(); ?></span>
													<?php esc_html_e('Reviews', 'triptip'); ?>
												</li>
											<?php } ?>
										</ul>
									</div>
									<!-- End Author-wrapper module-->
								</div>
							<?php } ?>
							<?php 
								if(is_active_sidebar('sidebar-list')){
									dynamic_sidebar('sidebar-list');
								}
							?>

						</div>
					</div>
				</div>
			</div>
		</div>
		
	</section>
	<!-- End listing-detail -->
<?php endwhile; ?>