<?php 
global $post,$elonissa_fn_option;
$key = 0;
$postType	= 'post';
$list 		= '';
if(is_front_page()) {
	$elonissa_fn_paged = (get_query_var('page')) ? get_query_var('page') : 1;
} else {
	$elonissa_fn_paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
}
if(!is_search() && !is_archive() && !is_home()){
	query_posts('posts_per_page=&paged='.esc_html($elonissa_fn_paged));
}


$from_page			= 'blog';
if (isset($args['from_page'])) {
	$from_page 		= $args['from_page'];
}
if (have_posts()) : while (have_posts()) : the_post();
	$key++;
	$postID 		= get_the_id();
	$permalink 		= get_the_permalink();
	$title			= get_the_title();
	$postClasses  	= 'class="'.implode(' ', get_post_class()).' item"';
	$fullImageURL	= get_the_post_thumbnail_url($postID,'full');
	$hasImage		= $fullImageURL == '' ? 0 : 1; 

	

	// Image
	if($from_page == 'search'){
		$post_image = '<a href="'.$permalink.'"></a><span data-fn-bg-img="'.$fullImageURL.'"></span>';
	}else{
		$post_image = '<a href="'.$permalink.'"><img src="'.$fullImageURL.'" /></a>';
	}
	$img_wrap		= '<div class="img_wrap" data-has="'.$hasImage.'">'.$post_image.'</div>';
	
	// Title
	$post_title		= '';
	if($title !== ''){
		$post_title = '<div class="post_title"><h3><a href="'.$permalink.'">'.$title.'</a></h3></div>';
	}

	// Description
	$post_desc		= elonissa_fn_excerpt(22,$postID);
	if($post_desc != ''){
		$post_desc 	= '<div class="excerpt_holder"><p>'.$post_desc.'</p></div>';
	}
	
	// Read More Button / Category / Extra Meta
	if($from_page == 'search'){	
		$post_read 	= '<div class="read_more"><a href="'.$permalink.'">'.esc_html__('Continue Reading', 'elonissa').'</a></div>';
		$category	= '';
		$extra_meta	= '';
	}else{
		$category	= elonissa_fn_get_category_info($postID,$postType);
		$post_read 	= elonissa_fn_read_more();
		$extra_meta	= elonissa_fn_meta();
	}
	

	// Opener and closer
	$post_header 	= '<li class="fn_post_item_'.$key.'" id="post-'.$postID.'"><div '.$postClasses.'>';
	$post_footer 	= '</div></li>';
	
	// Title Holder
	$title_holder	= '<div class="title_holder">'.$category.$post_title.$post_desc.$post_read.'</div>';


	// echo
	$list .= $post_header;
		$list .= $img_wrap;
		$list .= $title_holder;
		$list .= $extra_meta;
	$list .= $post_footer;

endwhile; endif; wp_reset_postdata();
echo wp_kses($list, 'post');
?>