<?php
/**
 * This file is used to show related posts on your single blog posts
 * @package S-corp WordPress Theme
 * @since 1.0
 * @author WPExplorer : http://www.wpexplorer.com
 * @copyright Copyright (c) 2012, WPExplorer
 * @link http://www.wpexplorer.com
 */

$wpex_related_category = NULL;
$wpex_related_category = get_the_category(); //get first current category ID

$args = array(
	'numberposts' 		=> 9,
	'orderby' 			=> 'rand',
	'category' 			=> $wpex_related_category[0]->cat_ID,
	'exclude' 			=> get_the_ID(),
	'offset' 			=> null,
	'no_found_rows'		=> true,
	'suppress_filters'	=> false, // WPML support
);
$posts = get_posts($args);
if( $posts ) {
	
	// Load carousel scripts
	wp_enqueue_style('bxslider');
	wp_enqueue_script('wpex-related-posts-carousel'); ?>
    
    <section id="related-posts" class="clearfix">
        <h4 class="symple-heading lined text-align-left"><span><?php echo __('More In ','wpex') . $wpex_related_category[0]->name; ?></span></h4>
        <ul <?php if( count( $posts ) > 3 ) echo 'id="related-posts-carousel"'; ?>>
		<?php foreach($posts as $post) : setup_postdata($post); ?>
        	<li class="related-post clearfix">
                <?php if( has_post_thumbnail() ) { ?>
                	<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="related-post-thumbnail">
                    	<img src="<?php echo aq_resize( wp_get_attachment_url( get_post_thumbnail_id() ), 190, 135, true ); ?>" alt="<?php the_title(); ?>" />
                    </a>
                <?php } ?>
                <div class="related-post-details">
                	<h5 class="related-post-title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h5>
                	<p class="related-post-excerpt"><?php echo wp_trim_words( strip_shortcodes( get_the_content() ), 15, '&hellip;' ); ?></p>
                </div><!-- /related-post-description -->
            </li>
        <?php
        endforeach;
		wp_reset_postdata();$wpex_related_category = NULL; ?>
        </ul>
    </section> <!-- /related-posts --> 
<?php } // no posts found