<?php
/**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site may use a
 * different template.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package newshit
 */

get_header();

?>

	<?php 
		/**
		* Hook - newshit_action_before_single_page.
		*
		* @hooked newshit_single_page_start
		*/
		do_action( 'newshit_action_before_single_page' );
	?>

		<div class="col-12 col-lg-8">
            <?php
                $taxonomy = get_queried_object();
                $the_query = new WP_Query( array(
                    'post_type' => 'web-story',
                    'posts_per_page' => -1,
                    'tax_query' => array(
                        array (
                            'taxonomy' => 'web_story_category',
                            'field' => 'slug',
                            'terms' =>$taxonomy->slug,
                        )
                    ),
                ) );

                while ( $the_query->have_posts() ) :
                    $the_query->the_post();
                   ?>   
                        <div class="single-post-item">
                            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                                <div class="single-post-wrapper">
                            
                                    <?php if ( has_post_thumbnail() ) : ?>
                                        <div class="post-thumbnail-wrapper">
                                            <img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'newshit-large' ) ?>"
                                                alt="<?php echo get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ); ?>">
                                        </div>
                                    <?php endif; ?>
                                
                                    <div class="post-content-wrapper">

                                        <div class="post-meta">
                                            <ul>
                                                <li><?php newshit_posted_by(); ?></li>
                                                <li><?php newshit_posted_on(); ?></li>
                                                <li><?php newshit_story_all_post_cat(); ?></li> 
                                            </ul>
                                        </div>

                                        <h2 class="post-title"><a href="<?php echo esc_url( get_the_permalink() ); ?>"><?php the_title(); ?></a></h2>

                                        
                                        <div class="post-excerpt">
                                            <p>
                                                <?php echo newshit_words_limit( get_the_excerpt(), 10 ); ?>
                                                    <?php if ( ! empty( get_the_content() ) ) {
                                                    echo ' [...]';
                                                } ?>
                                            </p>
                                        </div>
                                        <div class="post-footer">
                                            <div class="post-read-more">
                                                <a href="<?php echo esc_url( get_the_permalink() ); ?>"><?php echo esc_html( get_theme_mod( 'btn_text', 'Read More' ) ); ?><i class="fas fa-angle-double-right"></i></a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </article>
                        </div>
                   <?php 
                endwhile;
                wp_reset_postdata();
                
            ?>

            
		</div>

        <div class="col-12 col-lg-4">
            <?php get_sidebar(); ?>
        </div>
		
		<?php 
	/**
	* Hook - newshit_action_after_single_page.
	*
	* @hooked newshit_single_page_end
	*/
	do_action( 'newshit_action_after_single_page' );
	?>
<?php get_footer();
