<?php
/**
 * The template for displaying all single posts.
 *
 * @package SociallyViral
 */

get_header(); ?>

<div class="breadcrumb" xmlns:v="http://rdf.data-vocabulary.org/#"><?php sociallyviral_the_breadcrumb(); ?></div>
	<div class="single_post">
		<main id="content_box" class="site-single" role="single">
			<?php while ( have_posts() ) : the_post(); ?>
				<?php get_template_part( 'content', 'single' ); ?>
			<?php endwhile; // end of the loop. ?>
			
			<div class="post-tags"><?php the_tags(); ?></div>

			<!-- Related Posts -->
			<div class="related-posts">
				<h4><?php _e('You may also like', 'sociallyviral') ?></h4>
				<div class="crd">
				<?php global $post;
				$thePostID = $post->ID;
				$cats = get_the_category($thePostID);
				$cat_ids = array();
				foreach($cats as $individual_cat)
					$cat_ids[] = $individual_cat->cat_ID;
					$posts = new WP_Query( 
						array(
							'category__in' => $cat_ids,
							'post__not_in' => array($thePostID),
							'posts_per_page' => 4, 
							'orderby' => 'rand'
							)
						);
					while ( $posts->have_posts() ) { $posts->the_post(); ?>
						<article id="post <?php the_ID(); ?>" <?php post_class('latestpost '.$post_class); ?>>
					<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="nofollow" id="featured-thumbnail">
    				 <div class="featured-thumbnail">
    <?php 
    if (has_post_thumbnail()) {
        the_post_thumbnail($image_size, ['title' => '']);
    } else {
        $first_img = get_first_image_from_post(get_the_ID());
        if ($first_img) {
            echo '<img src="' . esc_url($first_img) . '" alt="' . esc_attr(get_the_title()) . '" />';
        } else {
            echo '<img src="' . sociallyviral_get_thumbnail_url($image_size == 'full' ? 'full' : 'full') . '" alt="' . esc_attr(get_the_title()) . '" />';
        }
    }
    ?>
</div>
    				    <?php if($image_size == 'sociallyviral_featuredbig'){ ?>
							<div class="post-label"><i class="icon-star"></i><span><?php _e('Featured','sociallyviral'); ?></span></div>
						<?php } ?>
    				</a>
					<header class="entry-header">
						<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
					
					</header><!-- .entry-header -->
				</article>
				<?php } wp_reset_postdata(); ?>
				</div>
			</div>

					<?php // If comments are open or we have at least one comment, load up the comment template
			if ( comments_open() || get_comments_number() ) :
				comments_template();
			endif; ?>

		</main><!-- #main -->
	<?php get_sidebar(); ?>
	</div><!-- single_post -->

<?php get_footer(); ?>
