<?php 

/**
*  Main Slider Loop Hook
*/
if ( ! function_exists( 'newshit_news_main_slider_loop_hook' ) ) :

    /**
     * breadcrumb
     *
     * @since 1.0.0
     */
    function newshit_news_main_slider_loop_hook(){

        if( is_plugin_active( 'web-stories/web-stories.php' ) && 'web-story' === get_theme_mod('slider_post_type', 'post' ) ){
            $post_type = 'web-story';
        }else{
            $post_type = 'post';
        }
        if( 'web-story' == $post_type && true === get_theme_mod('enable_slider_story_filter' ) && !empty( get_theme_mod( 'slider_story_filter_cat', '' ) )){
            $p = new \WP_Query( array( 
                'posts_per_page' => get_theme_mod( 'main_slider_post_number', 30 ),
                'post_type' => 'web-story',
                'orderby'        => get_theme_mod( 'news_main_slider_postby' ),
                'order'          => get_theme_mod( 'news_main_slider_order' ),
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'web_story_category',
                        'terms'    => get_theme_mod( 'slider_story_filter_cat' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }elseif( 'post' == $post_type && 'one' === get_theme_mod( 'main_slider_filter_select','one' ) && !empty( get_theme_mod( 'main_slider_post_cat', '' ) )){
            $p = new \WP_Query( array( 
                'posts_per_page' => get_theme_mod( 'main_slider_post_number', 10 ),
                'post_type' => 'post',
                'orderby'        => get_theme_mod( 'news_main_slider_postby' ),
                'order'          => get_theme_mod( 'news_main_slider_order' ),
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'category',
                        'terms'    => get_theme_mod( 'main_slider_post_cat' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }elseif( 'post' == $post_type && 'two' === get_theme_mod('main_slider_filter_select' ) && !empty( get_theme_mod( 'main_slider_post_tag', '' ) )){
            $p = new \WP_Query( array( 
                'posts_per_page' => get_theme_mod( 'main_slider_post_number', 10 ),
                'post_type' => 'post',
                'orderby'        => get_theme_mod( 'news_main_slider_postby' ),
                'order'          => get_theme_mod( 'news_main_slider_order' ),
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'post_tag',
                        'terms'    => get_theme_mod( 'main_slider_post_tag' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }else{
            $p = new \WP_Query( array( 
                'posts_per_page' => get_theme_mod( 'main_slider_post_number', 10 ),
                'post_type'      => $post_type,
                'orderby'        => get_theme_mod( 'news_main_slider_postby' ),
                'order'          => get_theme_mod( 'news_main_slider_order' ),
            ));
        }
        ?>
        <?php while ( $p->have_posts() ): $p->the_post(); ?>
        <div class="newshit-post-item <?php echo esc_attr( 'two' === get_theme_mod( 'select_news_main_section', 'one' ) ? 'muckup-two' : 'muckup-one newshit-gradent' ); ?>">
            <div class="newshit-post-thumbnail-wrapper">
                <?php if( has_post_thumbnail() ) : ?>
                    <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 ); ?>">
                <?php endif; ?>
            </div>
            <div class="newshit-post-item-content">

                <?php if( true === get_theme_mod( 'enable_slider_cat', true ) ) : ?>
                    <div class="newshit-post-catagory">
                        <?php
                        if( 'post' === get_theme_mod('slider_post_type', 'post' ) ){
                            newshit_front_post_cat();
                        }else{
                            newshit_story_front_post_cat();
                        } ?>
                    </div>
                <?php endif; ?>

                <?php if( true === get_theme_mod( 'enable_slider_title', true ) ) : ?>
                    <<?php echo esc_attr( get_theme_mod( 'slider_title_tag', 'h2' ) ); ?> class="newshit-post-title"> 
                        <a href="<?php echo esc_url(the_permalink()); ?>"><?php echo newshit_words_limit( get_the_title(), get_theme_mod( 'main_slider_title_lanth', 20 ) ); ?></a>
                    </<?php echo esc_attr( get_theme_mod( 'slider_title_tag', 'h2' ) ); ?>>
                <?php endif;?>
                
                <?php if( true === get_theme_mod( 'enable_slider_post_metabox', true ) ) : ?>
                    <div class="newshit-post-meta">
                        <ul>
                            <?php
                            $main_slider_meta = get_theme_mod('main_slider_meta');
                            $default_meta = array('author', 'date', 'comment');
                            
                            // If no values are set, use the default values
                            if (empty($main_slider_meta) || !is_array($main_slider_meta)) {
                                $main_slider_meta = $default_meta;
                            }

                            foreach( $main_slider_meta as $newshit_meta  ) : ?>
                                <?php if( $newshit_meta == 'author'  ) : ?>
                                    <li><?php newshit_posted_by(); ?></li>
                                <?php endif; ?>

                                <?php if( $newshit_meta == 'date' ) : ?>
                                    <li><?php newshit_posted_on(); ?></li>
                                <?php endif; ?>

                                <?php if( $newshit_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                    <li class="comment-number"><?php newshit_comment_count(); ?></li>
                                <?php endif; ?>
                            <?php  endforeach; ?>
                        </ul>
                    </div>
                <?php endif; ?>
            </div>        
        </div>
        <?php endwhile; wp_reset_query(); ?>
        <?php 
    }
endif;
add_action( 'newshit_news_main_slider_loop_action', 'newshit_news_main_slider_loop_hook' );


/**
 * Main Section Tranding Hook Item
 */
if ( ! function_exists( 'newshit_news_tranding_hook' ) ) :

    /**
     * breadcrumb
     *
     * @since 1.0.0
     */
    function newshit_news_tranding_hook(){
        ?>
        <div class="post-small-items item-scrill">
            <?php 
            if( is_plugin_active( 'web-stories/web-stories.php' ) && 'web-story' === get_theme_mod('tab1_post_type', 'post' ) ){
                $post_type = 'web-story';
            }else{
                $post_type = 'post';
            }
            if( 'web-story' == $post_type && true === get_theme_mod('enable_tab1_story_filter' ) && !empty( get_theme_mod( 'tab1_story_filter_cat', '' ) )){
                $p = new \WP_Query( array( 
                    'posts_per_page' => get_theme_mod( 'tab1_dispaly_item', 10 ),
                    'post_type' => 'web-story',
                    'orderby'        => get_theme_mod( 'tab1_post_orderby' ),
                    'order'          => get_theme_mod( 'tab1_post_order' ),
                    'tax_query'      => array(
                        array(
                            'taxonomy' => 'web_story_category',
                            'terms'    => get_theme_mod( 'tab1_story_filter_cat' ),
                            'field' => 'term_id',
                        )
                    )
                ));
            }elseif( 'post' == $post_type && true === get_theme_mod( 'enable_tab1_post_filter', true ) && 'one' === get_theme_mod( 'tab1_post_filter','one' ) && !empty( get_theme_mod( 'tab1_post_cat', '' ) )){
                $p = new \WP_Query( array( 
                    'posts_per_page' => get_theme_mod( 'tab1_dispaly_item', 10 ),
                    'post_type' => 'post',
                    'orderby'        => get_theme_mod( 'tab1_post_orderby' ),
                    'order'          => get_theme_mod( 'tab1_post_order' ),
                    'tax_query'      => array(
                        array(
                            'taxonomy' => 'category',
                            'terms'    => get_theme_mod( 'tab1_post_cat' ),
                            'field' => 'term_id',
                        )
                    )
                ));
            }elseif( 'post' == $post_type && true === get_theme_mod( 'enable_tab1_post_filter', true ) && 'two' === get_theme_mod('tab1_post_filter' ) && !empty( get_theme_mod( 'tab1_post_tag', '' ) )){
                $p = new \WP_Query( array( 
                    'posts_per_page' => get_theme_mod( 'tab1_dispaly_item', 10 ),
                    'post_type' => 'post',
                    'orderby'        => get_theme_mod( 'tab1_post_orderby' ),
                    'order'          => get_theme_mod( 'tab1_post_order' ),
                    'tax_query'      => array(
                        array(
                            'taxonomy' => 'post_tag',
                            'terms'    => get_theme_mod( 'tab1_post_tag' ),
                            'field' => 'term_id',
                        )
                    )
                ));
            }else{
                $p = new \WP_Query( array( 
                    'posts_per_page' => get_theme_mod( 'tab1_dispaly_item', 10 ),
                    'post_type'      => $post_type,
                    'orderby'        => get_theme_mod( 'tab1_post_orderby' ),
                    'order'          => get_theme_mod( 'tab1_post_order' ),
                ));
            }
            ?>
            <?php while ( $p->have_posts() ): $p->the_post(); ?>
            <div class="post-small-item">
                <div class="post-small-image">
                    <?php if( has_post_thumbnail() ) : ?>
                        <a href="<?php echo esc_url(the_permalink()); ?>">
                            <img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'thumbnail' ) ?>" alt="<?php echo get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ); ?>">
                        </a>
                    <?php endif; ?>
                </div>
                <div class="post-small-content">
                    <?php if( true === get_theme_mod( 'enable_tab1_meta_items', true ) ) : ?>
                    <div class="post-small-meta">
                        <ul>
                            <?php 
                            $tab1_meta_items = get_theme_mod('tab1_meta_items');
                            $default_meta = array('author', 'date', 'cats');
                            
                            // If no values are set, use the default values
                            if (empty( $tab1_meta_items) || !is_array($tab1_meta_items )) {
                                $tab1_meta_items = $default_meta;
                            }

                            foreach( $tab1_meta_items as $newshit_meta  ) : ?>
                                <?php if( $newshit_meta == 'author'  ) : ?>
                                    <li><?php newshit_posted_by(); ?></li>
                                <?php endif; ?>

                                <?php if( $newshit_meta == 'date' ) : ?>
                                    <li><?php newshit_posted_on(); ?></li>
                                <?php endif; ?>

                                <?php if( $newshit_meta == 'cats' ) : ?>
                                    <li>
                                        <?php
                                            if( 'post' === get_theme_mod('tab1_post_type', 'post' ) ){
                                                newshit_post_first_category();
                                            }else{
                                                newshit_story_post_cat();
                                            } 
                                        ?>
                                    </li>
                                <?php endif; ?>
                               
                            <?php  endforeach; ?>
                        </ul>
                    </div>
                    <?php endif; ?>
                    <h4 class="post-small-title">
                        <a href="<?php echo esc_url(the_permalink()); ?>"><?php echo newshit_words_limit( get_the_title(), get_theme_mod( 'tab1_title_lanth', 7 ) ); ?></a>
                    </h4>
                </div>
            </div>
            <?php endwhile; wp_reset_query(); ?>
        </div>
        <?php 
    }
endif;
add_action( 'newshit_news_tranding_action', 'newshit_news_tranding_hook' );


/**
 * Main Section Most View Hook Item
 */
if ( ! function_exists( 'newshit_news_most_popular_hook' ) ) :

    /**
     * breadcrumb
     *
     * @since 1.0.0
     */
    function newshit_news_most_popular_hook(){
        ?>
       <div class="post-small-items item-scrill">
                            
        <?php 
            if( is_plugin_active( 'web-stories/web-stories.php' ) && 'web-story' === get_theme_mod('tab2_post_type', 'post' ) ){
                $post_type = 'web-story';
            }else{
                $post_type = 'post';
            }
            if( 'web-story' == $post_type && true === get_theme_mod('enable_tab2_story_filter' ) && !empty( get_theme_mod( 'tab2_story_filter_cat', '' ) )){
                $p2 = new \WP_Query( array( 
                    'posts_per_page' => get_theme_mod( 'tab2_dispaly_item', 10 ),
                    'post_type' => 'web-story',
                    'orderby'        => get_theme_mod( 'tab2_post_orderby' ),
                    'order'          => get_theme_mod( 'tab2_post_order' ),
                    'tax_query'      => array(
                        array(
                            'taxonomy' => 'web_story_category',
                            'terms'    => get_theme_mod( 'tab2_story_filter_cat' ),
                            'field' => 'term_id',
                        )
                    )
                ));
            }elseif( 'post' == $post_type && true === get_theme_mod( 'enable_tab2_post_filter', true ) && 'one' === get_theme_mod( 'tab2_post_filter','one' ) && !empty( get_theme_mod( 'tab2_post_cat', '' ) )){
                $p2 = new \WP_Query( array( 
                    'posts_per_page' => get_theme_mod( 'tab2_dispaly_item', 10 ),
                    'post_type' => 'post',
                    'orderby'        => get_theme_mod( 'tab2_post_orderby' ),
                    'order'          => get_theme_mod( 'tab2_post_order' ),
                    'tax_query'      => array(
                        array(
                            'taxonomy' => 'category',
                            'terms'    => get_theme_mod( 'tab2_post_cat' ),
                            'field' => 'term_id',
                        )
                    )
                ));
            }elseif( 'post' == $post_type && true === get_theme_mod( 'enable_tab2_post_filter', true ) && 'two' === get_theme_mod('tab2_post_filter' ) && !empty( get_theme_mod( 'tab2_post_tag', '' ) )){
                $p2 = new \WP_Query( array( 
                    'posts_per_page' => get_theme_mod( 'tab2_dispaly_item', 10 ),
                    'post_type' => 'post',
                    'orderby'        => get_theme_mod( 'tab2_post_orderby' ),
                    'order'          => get_theme_mod( 'tab2_post_order' ),
                    'tax_query'      => array(
                        array(
                            'taxonomy' => 'post_tag',
                            'terms'    => get_theme_mod( 'tab2_post_tag' ),
                            'field' => 'term_id',
                        )
                    )
                ));
            }else{
                $p2 = new \WP_Query( array( 
                    'posts_per_page' => get_theme_mod( 'tab2_dispaly_item', 10 ),
                    'post_type'      => $post_type,
                    'orderby'        => get_theme_mod( 'tab2_post_orderby' ),
                    'order'          => get_theme_mod( 'tab2_post_order' ),
                ));
            }
        ?>
        <?php while ( $p2->have_posts() ): $p2->the_post(); ?>
        <div class="post-small-item">
            <div class="post-small-image">
                <?php if( has_post_thumbnail() ) : ?>
                    <a href="<?php echo esc_url(the_permalink()); ?>">
                        <img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'thumbnail' ) ?>" alt="<?php echo get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ); ?>">
                    </a>
                <?php endif; ?>
            </div>
            <div class="post-small-content">
                <?php if( true === get_theme_mod( 'enable_tab2_meta_items', true ) ) : ?>
                    <div class="post-small-meta">
                        <ul>
                            <?php 
                            
                            $tab2_meta_items = get_theme_mod('tab2_meta_items');
                            $default_meta = array('author', 'date', 'cats');
                            
                            // If no values are set, use the default values
                            if (empty( $tab2_meta_items ) || !is_array($tab2_meta_items )) {
                                $tab2_meta_items = $default_meta;
                            }
                            
                            foreach( $tab2_meta_items as $newshit_meta  ) : ?>
                                <?php if( $newshit_meta == 'author'  ) : ?>
                                    <li><?php newshit_posted_by(); ?></li>
                                <?php endif; ?>

                                <?php if( $newshit_meta == 'date' ) : ?>
                                    <li><?php newshit_posted_on(); ?></li>
                                <?php endif; ?>
                                
                                <?php if( $newshit_meta == 'cats' ) : ?>
                                    
                                    <li>
                                        <?php
                                            if( 'post' === get_theme_mod('tab2_post_type', 'post' ) ){
                                                newshit_post_first_category();
                                            }else{
                                                newshit_story_post_cat();
                                            } 
                                        ?> 
                                    </li>
                                <?php endif; ?>
                                
                            <?php  endforeach; ?>
                        </ul>
                    </div>
                <?php endif; ?>
                <h4 class="post-small-title">
                    <a href="<?php echo esc_url(the_permalink()); ?>"><?php echo newshit_words_limit( get_the_title(), get_theme_mod( 'tab2_title_lanth', 7 ) ); ?></a>
                </h4>
            </div>
        </div>
        <?php endwhile; wp_reset_query(); ?>
    </div>
        <?php 
    }
endif;
add_action( 'newshit_news_most_popular_action', 'newshit_news_most_popular_hook' );



/**
*  Featured Section Loop Hook
*/
if ( ! function_exists( 'newshit_featured_section_loop' ) ) :
    function newshit_featured_section_loop(){

        if( true === get_theme_mod( 'enable_featured_slider', true  ) ){
            $dispaly = -1;
        }else{
            $dispaly = get_theme_mod( 'featured_dispaly_number', 4 );
        }
        if( is_plugin_active( 'web-stories/web-stories.php' ) && 'web-story' === get_theme_mod('featured_post_type', 'post' ) ){
            $post_type = 'web-story';
        }else{
            $post_type = 'post';
        }
        if( 'web-story' == $post_type && true === get_theme_mod('enable_featured_story_filter' ) && !empty( get_theme_mod( 'featured_story_filter_cat', '' ) )){
            $p = new \WP_Query( array( 
                'posts_per_page' => $dispaly,
                'post_type' => 'web-story',
                'orderby'        => get_theme_mod( 'news_featured_postby' ),
                'order'          => get_theme_mod( 'news_featured_order' ),
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'web_story_category',
                        'terms'    => get_theme_mod( 'featured_story_filter_cat' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }elseif( 'post' == $post_type && true === get_theme_mod( 'enable_featured_filter', true ) && 'one' === get_theme_mod( 'featured_select_filter','one' ) && !empty( get_theme_mod( 'main_feature_post_cat', '' ) )){
            $p = new \WP_Query( array( 
                'posts_per_page' => $dispaly,
                'post_type' => 'post',
                'orderby'        => get_theme_mod( 'news_featured_postby' ),
                'order'          => get_theme_mod( 'news_featured_order' ),
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'category',
                        'terms'    => get_theme_mod( 'main_feature_post_cat' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }elseif( 'post' == $post_type && true === get_theme_mod( 'enable_featured_filter', true ) && 'two' === get_theme_mod('featured_select_filter' ) && !empty( get_theme_mod( 'main_featured_post_tag', '' ) )){
            $p = new \WP_Query( array( 
                'posts_per_page' => $dispaly,
                'post_type' => 'post',
                'orderby'        => get_theme_mod( 'news_featured_postby' ),
                'order'          => get_theme_mod( 'news_featured_order' ),
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'post_tag',
                        'terms'    => get_theme_mod( 'main_featured_post_tag' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }else{
            $p = new \WP_Query( array( 
                'posts_per_page' => $dispaly,
                'post_type'      => $post_type,
                'orderby'        => get_theme_mod( 'news_featured_postby' ),
                'order'          => get_theme_mod( 'news_featured_order' ),
            ));
        }
        ?>
        <?php while ( $p->have_posts() ): $p->the_post(); ?>
        <div class="col-12 col-sm-6 col-md-4 col-lg-4 col-xl-3">
            <div class="newshit-post-item muckup-one newshit-gradent newshit-post-item-medium">
                <div class="newshit-post-thumbnail-wrapper">
                    <?php if( has_post_thumbnail() ) : ?>
                        <img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'full' ) ?>"
                        alt="<?php echo get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ); ?>">
                    <?php endif; ?>
                </div>
                <div class="newshit-post-item-content">

                    <?php if( true === get_theme_mod( 'enable_featured_cat', true ) ) : ?>
                        <div class="newshit-post-catagory">
                            <?php
                                if( 'post' === get_theme_mod('featured_post_type', 'post' ) ){
                                    newshit_front_post_cat();
                                }else{
                                    newshit_story_front_post_cat();
                                } 
                            ?>
                        </div>
                    <?php endif; ?>

                    <?php if( true === get_theme_mod( 'enable_featured_title', true ) ) : ?>
                        <<?php echo esc_attr( get_theme_mod( 'feature_title_tag', 'h2' ) ); ?> class="newshit-post-title"> 
                            <a href="<?php echo esc_url(the_permalink()); ?>"><?php echo newshit_words_limit( get_the_title(), get_theme_mod( 'main_feature_title_lanth', 20 ) ); ?></a>
                        </<?php echo esc_attr( get_theme_mod( 'feature_title_tag', 'h2' ) ); ?>>
                    <?php endif;?>
                    
                    <?php if( true === get_theme_mod( 'enable_featured_meta', false ) && !empty( get_theme_mod( 'main_feature_meta' ) ) ) : ?>
                        <div class="newshit-post-meta">
                            <ul>
                                <?php foreach( get_theme_mod( 'main_feature_meta' ) as $newshit_meta  ) : ?>
                                    <?php if( $newshit_meta == 'author'  ) : ?>
                                        <li><?php newshit_posted_by(); ?></li>
                                    <?php endif; ?>

                                    <?php if( $newshit_meta == 'date' ) : ?>
                                        <li><?php newshit_posted_on();  ?></li>
                                    <?php endif; ?>

                                    <?php if( $newshit_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                        <li class="comment-number"><?php newshit_comment_count(); ?></li>
                                    <?php endif; ?>
                                <?php  endforeach; ?>
                            </ul>
                        </div>
                    <?php endif; ?>
                    
                </div>        
            </div>
        </div>
        <?php endwhile; wp_reset_query(); ?>
        <?php 
    }
endif;
add_action( 'newshit_featured_section_loop_action', 'newshit_featured_section_loop' );




/**
*  Category Post Section Hook
*/
if ( ! function_exists( 'newshit_category_section_post_loop' ) ) :
    function newshit_category_section_post_loop(){ ?>
    
    <?php 
    if( true == get_theme_mod( 'show_by_category', true ) ){
        $p = new \WP_Query( array( 
            'posts_per_page' => get_theme_mod( 'category_post_dispaly', 5 ),
            'post_type' => 'post',
            'orderby'        => get_theme_mod( 'category_post_orderby' ),
            'order'          => get_theme_mod( 'category_post_order' ),
            'tax_query'      => array(
                array(
                    'taxonomy' => 'category',
                    'terms'    => get_theme_mod( 'category_post_cat' ),
                    'field' => 'term_id',
                )
            )
        ));
    }else{
        $p = new \WP_Query( array( 
            'posts_per_page' => get_theme_mod( 'category_post_dispaly', 5 ),
            'post_type' => 'post',
            'orderby'        => get_theme_mod( 'category_post_orderby' ),
            'order'          => get_theme_mod( 'category_post_order' ),
        ));
    }
    $categorys = get_theme_mod( 'category_post_cat' );

    ?>
    <div class="newshit-category-post-wrapper pb-1">
        <div class="newshit-section-title">
            <div class="newshit-section-title-box">
                <span><?php echo esc_html( get_theme_mod( 'cat_section_title', 'Category Post' ) ); ?></span>
            </div>
            <div class="category-menu-wrapper">
                <ul>
                    <?php if( true === get_theme_mod( 'enable_cat_allshow', true ) ) : ?>
                        <li class="active" data-filter="*"><?php echo esc_html( get_theme_mod( 'cat_allshow_text', 'All Show' ) ); ?></li>
                    <?php endif; ?>
                    <?php if( true == get_theme_mod( 'show_by_category', false ) && !empty( $categorys )){
                        foreach( $categorys as $category ){
                            $cat_info = get_term( $category, 'category');
                            echo '<li data-filter=".'.esc_attr($cat_info->slug).'">'.esc_html($cat_info->name).'</li>';
                        }
                        
                    }else{
                        $args = array(
                            'orderby' => 'name',
                            'order' => 'ASC',
                            'parent' => 0
                        );
                        $default_cats = get_categories($args);
                        if( !empty($default_cats) && ! is_wp_error( $default_cats ) ){
                            foreach($default_cats as $default_cat){
                                echo '<li data-filter=".'.esc_attr($default_cat->slug).'">'.esc_html($default_cat->name).'</li>';
                            }
                        }
                    } ?>
                </ul>
            </div>
        </div>
        <div class="row newshit-caregory-post-list  newshit-masonry">
            <?php
                $count = 0;
                while ( $p->have_posts() ): $p->the_post();
                $count++;
                $categorys = get_the_terms( get_the_ID(), 'category' );
                if ( $categorys && ! is_wp_error( $categorys ) ) {
                    $category_lsit = array();
                    foreach ( $categorys as $category ) {
                        $category_lsit[] = $category->slug;
                    }
                    $category_show = join( " ", $category_lsit );
                    
                }else{
                    $category_show = '';
                }
                
            ?>
            <?php if( $count == 1 ) : ?>
                <div class="newshit-category-item Category-first-item newshit-post-item  muckup-two col-12 col-sm-12 col-md-6 col-lg-6">
                    <div class="newshit-post-thumbnail-wrapper">
                        <?php if( has_post_thumbnail() ) : ?>
                            <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 ); ?>">
                        <?php endif; ?>
                    </div>
                    <div class="newshit-post-item-content">

                        <?php if( true === get_theme_mod( 'enable_category1_cat_meta', true ) ) : ?>
                            <div class="newshit-post-catagory">
                                <?php newshit_front_post_cat(); ?>
                            </div>
                        <?php endif; ?>

                        <?php if( true === get_theme_mod( 'enable_category1_title', true ) ) : ?>
                            <<?php echo esc_attr( get_theme_mod( 'enable_category1_title_tag', 'h2' ) ); ?> class="newshit-post-title"> 
                                <a href="<?php echo esc_url(the_permalink()); ?>"><?php echo newshit_words_limit( get_the_title(), get_theme_mod( 'enable_category1_title_lanth', 20 ) ); ?></a>
                            </<?php echo esc_attr( get_theme_mod( 'enable_category1_title_tag', 'h2' ) ); ?>>
                        <?php endif;?>

                        <?php if( true === get_theme_mod( 'enable_category1_dec', true ) ) : ?>
                            <div class="post-content">
                                <?php echo newshit_words_limit( get_the_content(), get_theme_mod( 'enable_category1_dec_lanth', 20 ) ); ?>
                            </div>
                        <?php endif; ?>

                        <?php if( true === get_theme_mod( 'enable_category1_meta', true ) ) : ?>
                            <div class="newshit-post-meta">
                                <ul>
                                    <?php 

                                    $category1_meta_list = get_theme_mod('category1_meta_list');
                                    $default_meta = array('author', 'date', 'comment');
                                    
                                    // If no values are set, use the default values
                                    if (empty( $category1_meta_list ) || !is_array($category1_meta_list )) {
                                        $category1_meta_list = $default_meta;
                                    }
                                    
                                    foreach( $category1_meta_list as $newshit_meta  ) : ?>
                                        <?php if( $newshit_meta == 'author'  ) : ?>
                                            <li><?php newshit_posted_by(); ?></li>
                                        <?php endif; ?>

                                        <?php if( $newshit_meta == 'date' ) : ?>
                                            <li><?php newshit_posted_on(); ?></li>
                                        <?php endif; ?>

                                        <?php if( $newshit_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                            <li class="comment-number"><?php newshit_comment_count(); ?></li>
                                        <?php endif; ?>
                                    <?php  endforeach; ?>
                                </ul>
                            </div>
                        <?php endif; ?>

                    </div>        
                </div>
            <?php else : ?>
            <div class="newshit-category-item col-12 col-sm-12 col-md-6 col-lg-6 <?php echo esc_attr( $category_show); ?>">
                <div class="post-small-item">

                    <?php if( true === get_theme_mod( 'enable_category2_img', true ) ) : ?>
                        <div class="post-small-image">
                            <?php if( has_post_thumbnail() ) : ?>
                                <a href="<?php echo esc_url(the_permalink()); ?>">
                                    <img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'thumbnail' ) ?>" alt="<?php echo get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ); ?>">
                                </a>
                            <?php endif; ?>
                        </div>
                    <?php endif; ?>

                    <div class="post-small-content">

                        <?php if( true === get_theme_mod( 'enable_category2_meta', true ) ) : ?>
                            <div class="post-small-meta">
                                <ul>
                                    <?php 

                                     $category2_meta_list = get_theme_mod('category2_meta_list');
                                     $default_meta = array('author', 'date', 'cat');
                                     
                                     // If no values are set, use the default values
                                     if (empty( $category2_meta_list ) || !is_array($category2_meta_list )) {
                                         $category2_meta_list = $default_meta;
                                     }
                                    
                                    foreach( $category2_meta_list as $newshit_meta  ) : ?>
                                        <?php if( $newshit_meta == 'author'  ) : ?>
                                            <li><?php newshit_posted_by(); ?></li>
                                        <?php endif; ?>

                                        <?php if( $newshit_meta == 'date' ) : ?>
                                            <li><?php newshit_posted_on(); ?></li>
                                        <?php endif; ?>

                                        <?php if( $newshit_meta == 'cat' ) : ?>
                                            <li><?php newshit_post_first_category(); ?></li>
                                        <?php endif; ?>

                                        <?php if( $newshit_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                            <li class="comment-number"><?php newshit_comment_count(); ?></li>
                                        <?php endif; ?>

                                    <?php  endforeach; ?>
                                </ul>
                            </div>
                        <?php endif; ?>

                        <?php if( true === get_theme_mod( 'enable_category2_title', true  ) ) : ?>
                            <<?php echo esc_attr( get_theme_mod( 'enable_category2_title_tag', 'h2' ) ); ?> class="post-small-title">
                                <a href="<?php echo esc_url(the_permalink()); ?>"><?php echo newshit_words_limit( get_the_title(), get_theme_mod( 'enable_category2_title_lanth', 20 ) ); ?></a>
                            </<?php echo esc_attr( get_theme_mod( 'enable_category2_title_tag', 'h2' ) ); ?>>
                        <?php endif; ?>

                    </div>
                </div>
            </div>
            <?php endif; endwhile; wp_reset_query(); ?>
        </div>
    </div>
    <?php }

endif;
add_action( 'newshit_category_section_post_action', 'newshit_category_section_post_loop' );




/**
*  Category Post Section Hook
*/
if ( ! function_exists( 'newshit_recent_post_section_post_loop' ) ) :
    function newshit_recent_post_section_post_loop(){ ?>

        <?php 
        $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
        if( true === get_theme_mod( 'enable_recent_post_filter', true ) && 'one' === get_theme_mod( 'recent_post_select_filter','one' ) && !empty( get_theme_mod( 'front_recent_post_cat') )){
            $p = new \WP_Query( array( 
                'posts_per_page' => get_theme_mod( 'front_recent_post_dispaly', 3 ),
                'post_type' => 'post',
                'orderby'        => get_theme_mod( 'front_recent_post_postby' ),
                'order'          => get_theme_mod( 'front_recent_post_order' ),
                'paged'         => $paged,
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'category',
                        'terms'    => get_theme_mod( 'front_recent_post_cat' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }elseif( true === get_theme_mod( 'enable_recent_post_filter', true ) && 'two' === get_theme_mod('recent_post_select_filter' ) && !empty( get_theme_mod( 'front_recent_post_tag_seleted') )){
            $p = new \WP_Query( array( 
                'posts_per_page' => get_theme_mod( 'front_recent_post_dispaly', 3 ),
                'post_type' => 'post',
                'orderby'        => get_theme_mod( 'front_recent_post_postby' ),
                'order'          => get_theme_mod( 'front_recent_post_order' ),
                'paged'         => $paged,
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'post_tag',
                        'terms'    => get_theme_mod( 'front_recent_post_tag_seleted' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }else{
            $p = new \WP_Query( array( 
                'posts_per_page' => get_theme_mod( 'front_recent_post_dispaly', 8 ),
                'post_type' => 'post',
                'orderby'        => get_theme_mod( 'front_recent_post_postby','ID' ),
                'order'          => get_theme_mod( 'front_recent_post_order', 'ASC' ),
                'paged'         => $paged,
            ));
        }
        
        ?>

        <div class="newshit-front-recent-post-wrapper">

            <?php if( !empty( get_theme_mod( 'recent_section_title', 'Recent Post' ) ) ) : ?>
            <div class="newshit-section-title">
                <div class="newshit-section-title-box">
                    <span><?php echo esc_html( get_theme_mod( 'recent_section_title', 'Recent Post' ) ); ?></span>
                </div>
            </div>
            <?php endif; ?>

            <div class="newshit-front-recent-post-box">
                <?php while ( $p->have_posts() ): $p->the_post(); ?>
                    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <div class="newshit-front-recent-post-item newshit-post-item muckup-two">
                            <div class="row g-0">

                                <div class="col-12 col-md-5">
                                    <div class="newshit-post-thumbnail-wrapper">
                                        <?php if( has_post_thumbnail() ) : ?>
                                            <img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'full' ) ?>"
                                            alt="<?php echo get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ); ?>">
                                        <?php endif; ?>
                                    </div>
                                </div>

                                <div class="col-12 col-md-7">
                                    <div class="newshit-post-item-content">

                                        <?php if( true === get_theme_mod( 'enable_recent_cat', true ) ) : ?>
                                            <div class="newshit-post-catagory">
                                                <?php newshit_front_post_cat(); ?>
                                            </div>
                                        <?php endif; ?>

                                        <?php if( true === get_theme_mod( 'enable_recent_post_title', true ) ) : ?>
                                            <<?php echo esc_attr( get_theme_mod( 'recent_post_title_tag', 'h2' ) ); ?> class="newshit-post-title"> 
                                                <a href="<?php the_permalink(); ?>"><?php echo newshit_words_limit( get_the_title(), get_theme_mod( 'front_recent_post_title_lanth', 20 ) ); ?></a>
                                            </<?php echo esc_attr( get_theme_mod( 'recent_post_title_tag', 'h2' ) ); ?>>
                                        <?php endif;?>
                                        
                                        <?php if( true === get_theme_mod( 'enable_recent_post_meta', true ) ) : ?>
                                            <div class="newshit-post-meta">
                                                <ul>
                                                    <?php 

                                                    $front_recent_post_meta = get_theme_mod('front_recent_post_meta');
                                                    $default_meta = array('author', 'date', 'comment');
                                                    
                                                    // If no values are set, use the default values
                                                    if (empty( $front_recent_post_meta ) || !is_array( $front_recent_post_meta )) {
                                                        $front_recent_post_meta = $default_meta;
                                                    }
                                                    
                                                    
                                                    foreach( $front_recent_post_meta as $newshit_meta  ) : ?>
                                                        <?php if( $newshit_meta == 'author'  ) : ?>
                                                            <li><?php newshit_posted_by(); ?></li>
                                                        <?php endif; ?>

                                                        <?php if( $newshit_meta == 'date' ) : ?>
                                                            <li><?php newshit_posted_on(); ?></li>
                                                        <?php endif; ?>

                                                        <?php if( $newshit_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                                            <li class="comment-number"><?php newshit_comment_count(); ?></li>
                                                        <?php endif; ?>
                                                    <?php  endforeach; ?>
                                                </ul>
                                            </div>
                                        <?php endif; ?>

                                        <?php if( true === get_theme_mod( 'enable_recent_post_dec', true ) ) : ?>
                                            <div class="post-content">
                                                <?php echo newshit_words_limit( get_the_content(), get_theme_mod( 'front_recent_post_dec_lanth', 5 ) ); ?>
                                            </div>
                                        <?php endif; ?>

                                        <?php if( true === get_theme_mod( 'enable_recent_post_readmore', true ) ) : ?>
                                            <div class="newshit-post-readmore-box">
                                                <a href="<?php echo esc_url( get_the_permalink() ) ?>" class="newshit-post-readmore"><?php echo esc_html( get_theme_mod( 'recent_post_readmore_text', 'Read More' ) ); ?> <i class="fas fa-angle-double-right"></i></a>
                                            </div>
                                        <?php endif; ?>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </article>
                <?php endwhile; wp_reset_query(); ?>

                <?php
                    if( true === get_theme_mod( 'enable_recent_post_pagination', true ) ){
                        newshit_Post_pagination();
                    }
                ?>
                
            </div>
        </div>
<?php }

endif;
add_action( 'newshit_recent_post_section_post_action', 'newshit_recent_post_section_post_loop' );



/**
*  Front page Sidebar Hook
*/
if ( ! function_exists( 'newshit_home_sidebar_hook' ) ) :
    function newshit_home_sidebar_hook(){
        ?>
        <div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-4">
            <aside id="secondary" class="sidebar-widget-area home-widget-area">
                <?php dynamic_sidebar( get_theme_mod( 'select_home_sidebar', 'home-sidebar' ) ); ?>
            </aside><!-- #secondary -->
        </div>
        <?php 
    }
endif;
add_action( 'newshit_home_sidebar_action', 'newshit_home_sidebar_hook' );


/**
*  Most Liked Section Loop Hook
*/
if ( ! function_exists( 'newshit_most_liked_section_loop' ) ) :
    function newshit_most_liked_section_loop(){
        if( true === get_theme_mod( 'enable_most_liked_slider'  ) ){
            $dispaly = -1;
        }else{
            $dispaly = get_theme_mod( 'most_liked_dispaly_number', 8 );
        }
        if( is_plugin_active( 'web-stories/web-stories.php' ) && 'web-story' === get_theme_mod('mostlike_post_type', 'post' ) ){
            $post_type = 'web-story';
        }else{
            $post_type = 'post';
        }
        if( 'web-story' == $post_type && true === get_theme_mod('enable_mostlike_story_filter' ) && !empty( get_theme_mod( 'featured_story_filter_cat', '' ) )){
            $p = new \WP_Query( array( 
                'posts_per_page' => $dispaly,
                'post_type' => 'web-story',
                'orderby'        => get_theme_mod( 'news_most_liked_postby' ),
                'order'          => get_theme_mod( 'news_most_liked_order' ),
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'web_story_category',
                        'terms'    => get_theme_mod( 'featured_story_filter_cat' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }elseif( 'post' == $post_type && true === get_theme_mod( 'enable_most_liked_filter', true ) && 'one' === get_theme_mod( 'most_liked_select_filter','one' ) && !empty( get_theme_mod( 'main_most_liked_post_cat', '' ) )){
            $p = new \WP_Query( array( 
                'posts_per_page' => $dispaly,
                'post_type' => 'post',
                'orderby'        => get_theme_mod( 'news_most_liked_postby' ),
                'order'          => get_theme_mod( 'news_most_liked_order' ),
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'category',
                        'terms'    => get_theme_mod( 'main_most_liked_post_cat' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }elseif( 'post' == $post_type && true === get_theme_mod( 'enable_most_liked_filter', true ) && 'two' === get_theme_mod('most_liked_select_filter' ) && !empty( get_theme_mod( 'main_most_liked_post_tag', '' ) )){
            $p = new \WP_Query( array( 
                'posts_per_page' => $dispaly,
                'post_type' => 'post',
                'orderby'        => get_theme_mod( 'news_most_liked_postby' ),
                'order'          => get_theme_mod( 'news_most_liked_order' ),
                'tax_query'      => array(
                    array(
                        'taxonomy' => 'post_tag',
                        'terms'    => get_theme_mod( 'main_most_liked_post_tag' ),
                        'field' => 'term_id',
                    )
                )
            ));
        }else{
            $p = new \WP_Query( array( 
                'posts_per_page' => $dispaly,
                'post_type'      => $post_type,
                'orderby'        => get_theme_mod( 'news_most_liked_postby' ),
                'order'          => get_theme_mod( 'news_most_liked_order' ),
            ));
        }
        ?>
        <?php while ( $p->have_posts() ): $p->the_post(); ?>
        <div class="col-12 col-sm-6 col-md-4 col-lg-4 col-xl-3">
            <div class="newshit-post-item muckup-one newshit-gradent newshit-post-item-medium">
                <div class="newshit-post-thumbnail-wrapper">
                    <?php if( has_post_thumbnail() ) : ?>
                        <img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'full' ) ?>"
                        alt="<?php echo get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ); ?>">
                    <?php endif; ?>
                </div>
                <div class="newshit-post-item-content">

                    <?php if( true === get_theme_mod( 'enable_most_liked_cat', true ) ) : ?>
                        <div class="newshit-post-catagory">
                            <?php
                                if( 'post' === get_theme_mod('mostlike_post_type', 'post' ) ){
                                    newshit_front_post_cat();
                                }else{
                                    newshit_story_front_post_cat();
                                } 
                            ?>
                        </div>
                    <?php endif; ?>

                    <?php if( true === get_theme_mod( 'enable_most_liked_title', true ) ) : ?>
                        <<?php echo esc_attr( get_theme_mod( 'most_liked_title_tag', 'h2' ) ); ?> class="newshit-post-title"> 
                            <a href="<?php echo esc_url(the_permalink()); ?>"><?php echo newshit_words_limit( get_the_title(), get_theme_mod( 'main_most_liked_title_lanth', 20 ) ); ?></a>
                        </<?php echo esc_attr( get_theme_mod( 'most_liked_title_tag', 'h2' ) ); ?>>
                    <?php endif;?>
                    
                    <?php if( true === get_theme_mod( 'enable_most_liked_meta', false ) && !empty( get_theme_mod( 'main_most_liked_meta' ) ) ) : ?>
                        <div class="newshit-post-meta">
                            <ul>
                                <?php foreach( get_theme_mod( 'main_most_liked_meta' ) as $newshit_meta  ) : ?>
                                    <?php if( $newshit_meta == 'author'  ) : ?>
                                        <li><?php newshit_posted_by(); ?></li>
                                    <?php endif; ?>

                                    <?php if( $newshit_meta == 'date' ) : ?>
                                        <li><?php newshit_posted_on(); ?></li>
                                    <?php endif; ?>

                                    <?php if( $newshit_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                        <li class="comment-number"><?php newshit_comment_count(); ?></li>
                                    <?php endif; ?>
                                <?php  endforeach; ?>
                            </ul>
                        </div>
                    <?php endif; ?>
                    
                </div>        
            </div>
        </div>
        <?php endwhile; wp_reset_query(); ?>
        <?php 
    }
endif;
add_action( 'newshit_most_liked_section_loop_action', 'newshit_most_liked_section_loop' );