<?php
/**
 *  The template for displaying single blog post
 *
 *
 * @package Felicityhealth
 * @since Felicityhealth 1.0
 */
?>
<?php 
    get_header();
 ?>
 




 
<main role="main">
    <section class="container u-content-space u-bg-arrow-wrapper pb-4">
        <div class="row justify-content-center">
            <?php if ( have_posts() ) : ?>
            <?php while ( have_posts() ) : the_post(); ?>
            <?php get_template_part('template-parts/content','single'); ?>
            <?php
            if ( comments_open() || get_comments_number() ) {
                comments_template();
            }
            ?>
            <?php endwhile; ?>
            <?php endif; ?>

        </div><!-- .row -->

        <div class="row justify-content-center border-top mt-4">
            <div class="col-md-9">
                <div class="zulu-post-pagination">
                    <?php if (strlen(get_previous_post()->post_title) > 0) { //Check if next previous exist  ?>
                    <div class="zulu-post-prev">
                        <span>←&nbsp; <?php _e( 'Newer', 'zulured' ); ?></span>
                        <span class="subtitle"><?php previous_post_link( '<strong>%link</strong>' ); ?></span>
                    </div>
                    <?php } ?>
                    &nbsp;
                    <?php if (strlen(get_next_post()->post_title) > 0) { //Check if next post exist ?>
                    <div class="zulu-post-next">
                        <span><?php _e( 'Older', 'zulured' ); ?> &nbsp;→</span>
                        <span class="subtitle"><?php next_post_link( '<strong>%link</strong>' ); ?></span>
                    </div>
                    <?php } ?>
                </div>
            </div>
        </div>
    </section>

    <?php 
        // Display Related posts
		$orig_post = $post;
		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'=> 3, // Number of related posts that will be shown.
			'caller_get_posts'=>1
			);

			$my_query = new wp_query( $args );
			if( $my_query->have_posts() ) {?>
    <section class="container u-content-space u-bg-arrow-wrapper  pt-4">
        <div class="row mb-4">
            <div class="col">
                <div class="related-title">
                    <span class="h2"><?php _e( 'Related articles', 'zulured' ); ?></span>
                </div>
            </div>
        </div>

        <div class="row">
            <?php while( $my_query->have_posts() ) {
                                        $my_query->the_post();?>
            <?php get_template_part( 'template-parts/content' );?>
            <?php }?>
        </div>
    </section>
    <?php } } $post = $orig_post; wp_reset_query(); 
	?>

</main>


<?php get_footer(); ?>