<?php

function tie_last_posts($numberOfPosts = 5 , $thumb = true){
	global $post;
	$orig_post = $post;
	
	$lastPosts = get_posts('numberposts='.$numberOfPosts);
	foreach($lastPosts as $post): setup_postdata($post);
?>
<div class="column-post-item clearfix"><div class="column-post-thumb">
<?php if(has_post_thumbnail()){?><a href="<?php the_permalink(); ?>"><?php $ata = get_the_title(); if ( has_post_thumbnail()) the_post_thumbnail('img-145', array('title' => esc_attr( $post->post_title ) , 'alt' => $ata ) ); ?></a><?php }else{ ?><img src="<?php bloginfo("template_url"); ?>/img/none.png"><?php } ?></div>
<h3 class="post-title"><a href="<?php echo get_permalink( $post->ID ) ?>"><?php the_title(); ?></a></h3>
 </div>
<?php endforeach; 
	$post = $orig_post;
}
/*----------------------------------------Racent posts from Category-------------------------------------------*/

function tie_last_posts_cat($numberOfPosts = 5 , $thumb = true , $cats = 1){
	global $post;
	$orig_post = $post;

	$lastPosts = get_posts('category='.$cats.'&numberposts='.$numberOfPosts);
	foreach($lastPosts as $post): setup_postdata($post);
?>
<div class="column-post-item clearfix"><div class="column-post-thumb">
<?php if(has_post_thumbnail()){?><a href="<?php the_permalink(); ?>"><?php $ata = get_the_title(); if ( has_post_thumbnail()) the_post_thumbnail('img-145', array('title' => esc_attr( $post->post_title ) , 'alt' => $ata ) ); ?></a><?php }else{ ?><img src="<?php bloginfo("template_url"); ?>/img/none.png"><?php } ?></div>
<h3 class="post-title"><a href="<?php echo get_permalink( $post->ID ) ?>"><?php the_title(); ?></a></h3>
 </div>
<?php endforeach;
	$post = $orig_post;
}


/*--------------------------------------Popular posts ---------------------------------------------*/


function tie_popular_posts($pop_posts = 5 , $thumb = true){
	global $wpdb , $post;
	$orig_post = $post;
	
	$popularposts = "SELECT ID,post_title,post_date,post_author,post_content,post_type FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY comment_count DESC LIMIT 0,".$pop_posts;
	$posts = $wpdb->get_results($popularposts);
	if($posts){
		global $post;
		foreach($posts as $post){
		setup_postdata($post);?>
<div class="column-post-item clearfix"><div class="column-post-thumb">
<?php if(has_post_thumbnail()){?><a href="<?php the_permalink(); ?>"><?php $ata = get_the_title(); if ( has_post_thumbnail()) the_post_thumbnail('img-145', array('title' => esc_attr( $post->post_title ) , 'alt' => $ata ) ); ?></a><?php }else{ ?><img src="<?php bloginfo("template_url"); ?>/img/none.png"><?php } ?></div>
<h3 class="post-title"><a href="<?php echo get_permalink( $post->ID ) ?>"><?php the_title(); ?></a></h3>
 </div>
	<?php 
		}
	}
	$post = $orig_post;
}

/*------------------------------------------Reviews posts -----------------------------------------*/

function tie_best_reviews_posts($pop_posts = 5 , $thumb = true){
	global $post;
	$orig_post = $post;

	$cat_query1 = new WP_Query(array('posts_per_page' => $pop_posts, 'orderby' => 'meta_value_num' ,  'meta_key' => 'tie_review_score', 'post_status' => 'publish'));
	while ( $cat_query1->have_posts() ) : $cat_query1->the_post()?>
<div class="column-post-item clearfix"><div class="column-post-thumb">
<?php if(has_post_thumbnail()){?><a href="<?php the_permalink(); ?>"><?php $ata = get_the_title(); if ( has_post_thumbnail()) the_post_thumbnail('img-145', array('title' => esc_attr( $post->post_title ) , 'alt' => $ata ) ); ?></a><?php }else{ ?><img src="<?php bloginfo("template_url"); ?>/img/none.png"><?php } ?></div>
<h3 class="post-title"><a href="<?php echo get_permalink( $post->ID ) ?>"><?php the_title(); ?></a></h3>
 </div>
<?php endwhile;
	$post = $orig_post;
}
/*--------------------------------------commented posts ---------------------------------------------*/


function tie_most_commented($comment_posts = 5 , $avatar_size = 63){
$comments = get_comments('status=approve&number='.$comment_posts);
foreach ($comments as $comment) { ?>

			<div class="last-comment">			
            <div class="comment-image"><?php echo get_avatar( $comment, $avatar_size ); ?></div> 
            <div class="comment-txt"><a href="<?php echo get_permalink($comment->comment_post_ID ); ?>#comment-<?php echo $comment->comment_ID; ?>">
		<?php echo strip_tags($comment->comment_author); ?> » <?php echo wp_html_excerpt( $comment->comment_content, 110 ); ?>... </a></div> 
		   
			</div> 
	
<?php } 
}



?>