<?php
/**
 * Template part for displaying posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package OMag
 */

$theme_options = omag_theme_options();

?>

<article class="post type7">
	<div class="article-content article-title-meta">
	<div class="entry-header detail-entry-header">
		<h4>
			<?php the_title(); ?>
		</h4>
		<div class="banner-info">
			<?php
					if( 1 === $theme_options['single_post_author']) {
            		omag_posted_by();
        		} 
        		?>

        		<?php
					if( 1 === $theme_options['single_post_category']) { ?>

        		<span>-</span>
				<?php omag_posts_category(); ?>
				
			<?php } ?>
		</div>
		<div class="entry-meta">
			<?php
				if( 1 === $theme_options['single_post_date']) {
        			omag_posted_on();
    			}
    		?>

    		<?php
    			if( 1 === $theme_options['single_post_comments_count']) {
    				echo '<span class="comments-link">';
    				echo '<i class="far fa-comments"></i>';
    				comments_popup_link( esc_html__( 'No Comments', 'omag' ), esc_html__( '1 Comment', 'omag' ), '% '. esc_html__( 'Comments', 'omag' ), 'post-comments');
    				echo '</span>';
    			}
			?>
			</div>
		</div>
	</div>

	<?php if ( has_post_thumbnail() ) {  ?>

	<figure class="single-image">

		<?php the_post_thumbnail(); ?>
       
		<?php if( 1 === $theme_options['single_post_tags']) {
			omag_posts_tag();
		} ?>
	
	</figure>

	<?php } ?>



	<div class="article-content detail-article-content">
		<div class="entry-content detail-entry-content">
			<?php the_content(); ?>
		</div>

		<?php if( 1 === $theme_options['post_navigation']) { ?>

		<div class="pagination post-pagination">
			
			<?php the_post_navigation(); ?>
			
		</div>

		<?php } ?>



	</div>
</article>


<?php

    if( 1 === $theme_options['enable_related_posts']) {


?>


<div class="post-suggestion">
	<div class="suggestion-header">
		<h4> <span><?php echo esc_html( 'Related Articles', 'omag' ); ?> </span> </h4>
	</div>

	<?php
	    $OMAGurrentID = get_the_ID();

    $omag_post_cats = wp_get_object_terms($OMAGurrentID, 'category', array('fields' => 'ids'));


        $omag_post_args = array('post_type' => 'post',
                'tax_query' => array(
                    array(
                        'taxonomy' => 'category',
                        'field' => 'id',
                        'terms' => $omag_post_cats,
                    ),
                ),
                'posts_per_page'  => 3,
                'post__not_in' => array( $OMAGurrentID ),
             );

        $omag_post_query = new WP_Query( $omag_post_args );
  

    if ( $omag_post_query->have_posts() ) :
    	?>

	<div class="suggestion-content">
		<div class="row">

		<?php 
          while ( $omag_post_query->have_posts() ) : $omag_post_query->the_post();
         ?>

			<div class="col-lg-4">
				<article class="post type7">
					<figure>
						<a href="<?php the_permalink(); ?>">
						<?php if ( has_post_thumbnail() ) { 
                        	the_post_thumbnail('full'); ?>
                    	<?php } ?>
                    </a>
						<?php if( 1 === $theme_options['enable_post_tags']) {
							omag_posts_tag();
						} ?>
					</figure>
					<div class="article-content detail-article-content">
						<div class="entry-header detail-entry-header">
							<h4>
								<a href="<?php the_permalink(); ?>">
									<?php the_title(); ?>
								</a>
							</h4>
							<div class="banner-info">
								<?php
									if( 1 === $theme_options['enable_post_author']) {
			                		omag_posted_by();
			            		} 
			            		?>

			            		<?php
									if( 1 === $theme_options['enable_post_category']) { ?>

			            		<span>-</span>
								<?php omag_posts_category(); ?>
								
								<?php } ?>
							</div>
							<div class="entry-meta">
								<?php
									if( 1 === $theme_options['enable_post_date']) {
			                			omag_posted_on();
			            			}
			            		?>

			            		<?php
			            			if( 1 === $theme_options['enable_comments_count']) {
			            				echo '<span class="comments-link">';
			            				echo '<i class="far fa-comments"></i>';
			            				comments_popup_link( esc_html__( 'No Comments', 'omag' ), esc_html__( '1 Comment', 'omag' ), '% '. esc_html__( 'Comments', 'omag' ), 'post-comments');
			            				echo '</span>';
			            			}
			        			?>
							</div>
						</div>
					</div>
				</article>
			</div>


			<?php 

                endwhile;
                wp_reset_postdata();
            ?>


		</div>
	</div>

	 <?php
        endif;
        ?>
</div>

<?php
}
?>