<div class="related-posts">
<h3><?php echo __( 'Related Posts', 'lizard' )?>:</h3>
		<?php
		$postsCnt=3;
		$postid=$post->ID;
		$ids=array($postid);
		$tags=get_the_tags( $postid );
		$categories = get_the_category( $postid );
		$post_cnt=0;
		$first=0;
		if ($tags) {
			$tags_ids = array();
			foreach($tags as $tag) $tags_ids[] = $tag->term_id;
			$args=array(
			'tag__in' => $tags_ids,
			'post__not_in' => $ids,
			'showposts'=>$postsCnt,
			'ignore_sticky_posts'=>true);
			$posts=get_posts($args);
			if( count($posts)>0 ) {
				foreach ($posts as $p) {
					$post_cnt++;
					$ids[]=$p->ID;
				}
			}
		}
		if ($categories&&($post_cnt<$postsCnt)) {
			$category_ids = array();
			foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
			$args=array(
			'category__in' => $category_ids,
			'post__not_in' => $ids,
			'showposts'=>$postsCnt-$post_cnt,
			'ignore_sticky_posts'=>true);
			$posts=get_posts($args);
			if( count($posts)>0 ) {
				foreach ($posts as $p) {
					$post_cnt++;
					$ids[]=$p->ID;
				}
			}
		}
		if (!$post_cnt) {
			?><p><?php echo __( 'No related posts', 'lizard' )?></p><?php
		} else {
		
			unset($ids[0]);
			$args = array ( 'post__in' => $ids, 'posts_per_page' => $postsCnt );
			$items = new WP_Query( $args ); 
			while ( $items->have_posts() ) : $items->the_post(); 
			?>
				
				<div class='item'>
					<a href='<?php the_permalink(); ?>'>
						<?php echo get_the_post_thumbnail( $post->ID, 'related' ); ?>
						<h4><?php echo $post->post_title; ?></h4>
					</a>
					<div class="bgr"></div>
				</div>
			<?php endwhile;
			wp_reset_query(); 
		
		}
	?>
	<div class="clear"></div>
</div>