<?php 
/**
 * Trending news related posts functions
**/ 
?>
<?php 
function related_posts_tags($count=4) {
	
	//Related Posts by tags
	
		global $post;
		$tags = wp_get_post_tags($post->ID);
		
			if ($tags) {
				$tag_ids = array();
				
				foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
				
					$args=array(
						'tag__in' => $tag_ids,
						'post__not_in' => array($post->ID),
						'posts_per_page'=>$count, 
						'ignore_sticky_posts' => 1
							);
				
					$my_query = new wp_query( $args );		
					if( $my_query->have_posts() ) {
					echo '<div id="relatedposts"><ul class="featured-posts-category-small">';
					while( $my_query->have_posts() ) {
					$my_query->the_post(); ?>

                    <li>
                        <div class="small-featured-posts-image">
                            <?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) { ?>
                            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                            <?php the_post_thumbnail('small-thumb'); ?>
                            </a>
                            <?php } ?>
                        </div><!--small-featured-posts-image-->
                        <div class="small-featured-posts-text">
                            <h2><a href="<?php the_permalink() ?>" class="small-featured-posts-title">
                                <?php $tit = the_title('','',FALSE); echo substr($tit, 0, 45); if (strlen($tit) > 45) echo " ..."; ?>
                                </a></h2>
                            <div class="small-featured-posts-content">
                                <?php echo excerpt(10); ?>
                            </div><!--small-featured-posts-content-->	
                            <div class="small-featured-posts-date-posted">
                                <div class="post-date">
                                    <span class="date">Posted <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?></span>
                                </div><!--post-date-->
                            </div><!--small-featured-posts-date-posted--> 
                        </div><!--small-featured-posts-text--> 
                    </li>
<?php }	echo '</ul></div>';}}
		wp_reset_query();}	

function related_posts_category( $count=4) {
	
			//related posts by category

				global $post;
				$categories = get_the_category($post->ID);
				
					if ($categories) {
					$category_ids = array();
					foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
					$args=array(
						'category__in' => $category_ids,
						'post__not_in' => array($post->ID),
						'posts_per_page'=> $count, 
						'ignore_sticky_posts' => 1
							);

						$my_query = new wp_query( $args );
						if( $my_query->have_posts() ) {
						echo '<div id="related_posts"><ul class="featured-posts-category-small">';
						while( $my_query->have_posts() ) {
						$my_query->the_post();?>
                    <li>
                        <div class="small-featured-posts-image">
                            <?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) { ?>
                            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                            <?php the_post_thumbnail('small-thumb'); ?>
                            </a>
                            <?php } ?>
                        </div><!--small-featured-posts-image-->
                        <div class="small-featured-posts-text">
                            <h2><a href="<?php the_permalink() ?>" class="small-featured-posts-title">
                                <?php $tit = the_title('','',FALSE); echo substr($tit, 0, 45); if (strlen($tit) > 45) echo " ..."; ?>
                                </a></h2>
                            <div class="small-featured-posts-content">
                                <?php echo excerpt(10); ?>
                            </div><!--small-featured-posts-content-->	
                            <div class="small-featured-posts-date-posted">
                                <div class="post-date">
                                    <span class="date">Posted <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?></span>
                                </div><!--post-date-->
                            </div><!--small-featured-posts-date-posted--> 
                        </div><!--small-featured-posts-text--> 
                    </li>
<?php }	echo '</ul></div>';}}
		wp_reset_query();}
 
function related_posts_author($count=4) {

//related posts by author

				global $post;
				$author = get_the_author_meta('ID');
					
				$args=array(
					'author' => $author,
					'post__not_in' => array( $post->ID ),
					'posts_per_page' => $count );
			
					$my_query = new wp_query( $args );
					if( $my_query->have_posts() ) {
					echo '<div id="related_posts"><ul class="featured-posts-category-small">';
					while( $my_query->have_posts() ) {
					$my_query->the_post();?>
                    <li>
                        <div class="small-featured-posts-image">
                            <?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) { ?>
                            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                            <?php the_post_thumbnail('small-thumb');  ?>
                            </a>
                            <?php } ?>
                        </div><!--small-featured-posts-image-->
                        <div class="small-featured-posts-text">
                            <h2><a href="<?php the_permalink() ?>" class="small-featured-posts-title">
                                <?php $tit = the_title('','',FALSE); echo substr($tit, 0, 45); if (strlen($tit) > 45) echo " ..."; ?>
                                </a></h2>
                            <div class="small-featured-posts-content">
                                <?php echo excerpt(10); ?>
                            </div><!--small-featured-posts-content-->	
                            <div class="small-featured-posts-date-posted">
                                <div class="post-date">
                                    <span class="date">Posted <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?></span>
                                </div><!--post-date-->
                            </div><!--small-featured-posts-date-posted--> 
                        </div><!--small-featured-posts-text--> 
                    </li>
<?php }echo '</ul></div>';} wp_reset_query();} ?>