<?php 

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

    /**
     * Slider Section
     *
     * @since 1.0.0
     */
    function newscope_news_main_slider_loop_hook(){

        if( '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( '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',
                '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="swiper-slide">
            <div class="hero-slider">
                <div class="hero-img parallax-bg <?php echo esc_attr( has_post_thumbnail() != true ? 'card-bg-color' : '' ); ?>" data-swiper-parallax="-23%">
                    <?php if( has_post_thumbnail() ) : ?>
                        <img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'newscope-large' ) ?>"
                        alt="<?php echo get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ); ?>">
                    <?php endif; ?>
                </div>
                <div class="news-blog-card-content">
                    <?php if( true === get_theme_mod( 'enable_slider_cat', true ) ) : ?>
                        <div class="slider-cat" data-swiper-parallax="-100">
                            <?php newscope_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', 'h1' ) ); ?> class="content-title" data-swiper-parallax="-200"> 
                            <a href="<?php echo esc_url(get_the_permalink()); ?>"><?php echo newscope_words_limit( get_the_title(), get_theme_mod( 'main_slider_title_lanth', 20 ) ); ?></a>
                        </<?php echo esc_attr( get_theme_mod( 'slider_title_tag', 'h1' ) ); ?>>
                    <?php endif;?>
                    <div class="news-date-admin animate__animated animate__fadeInUp">
                        <?php if( true === get_theme_mod( 'enable_slider_post_metabox', true ) ) : ?>
                        <div class="newscope-post-meta" data-swiper-parallax="-300"
                        data-swiper-parallax-duration="600">
                            <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 $newscope_meta  ) : ?>
                                    <?php if( $newscope_meta == 'author'  ) : ?>
                                        <li><?php newscope_posted_by(); ?></li>
                                    <?php endif; ?>

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

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



/**
*  What A News Section Loop Hook
*/
if ( ! function_exists( 'newscope_what_a_news_section_loop' ) ) :
    function newscope_what_a_news_section_loop(){

        // Get theme modifications
        $enable_filter = get_theme_mod('enable_what_a_news_filter', true);
        $select_filter = get_theme_mod('what_a_news_select_filter', 'one');
        $cat = get_theme_mod('main_what_a_news_post_cat', '');
        $tag = get_theme_mod('main_what_a_news_post_tag', '');
        $posts_per_page = get_theme_mod('dispaly_what_a_news_items', 5);
        $order_by = get_theme_mod('news_what_a_news_postby');
        $order = get_theme_mod('news_what_a_news_order');

        // Set up query arguments
        $args = array(
            'posts_per_page' => $posts_per_page,
            'post_type' => 'post',
            'orderby' => $order_by,
            'order' => $order,
        );

        // Add taxonomy filter if enabled
        if ($enable_filter) {
            if ($select_filter === 'one' && !empty($cat)) {
                $args['tax_query'] = array(
                    array(
                        'taxonomy' => 'category',
                        'terms' => $cat,
                        'field' => 'term_id',
                    ),
                );
            } elseif ($select_filter === 'two' && !empty($tag)) {
                $args['tax_query'] = array(
                    array(
                        'taxonomy' => 'post_tag',
                        'terms' => $tag,
                        'field' => 'term_id',
                    ),
                );
            }
        }

        // Execute the query
        $p = new \WP_Query($args);
         $count = 0; while ( $p->have_posts() ): $p->the_post(); $count++; 
        ?>
        <?php if( 1 === $count ) : ?>
        <div class="col-lg-8">
            <div class="news-blog-card v1 first pb-4" data-aos="fade-right" data-aos-duration="800" data-aos-delay="100">
                <div class="news-blog-card-img <?php echo esc_attr( has_post_thumbnail() != true ? 'card-bg-color' : '' ); ?>">
                    <?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 class="news-blog-content position-absolate">
                        <?php if( true === get_theme_mod( 'enable_what_a_news_cat', true ) ){
                            echo '<div class="slider-cat">';
                            newscope_front_post_cat();
                            echo '</div>';
                        }?>
                        <<?php echo esc_attr( get_theme_mod( 'feature_title_tag', 'h3' ) ); ?> class="blog-title v1 title-font-size-30"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></<?php echo esc_attr( get_theme_mod( 'feature_title_tag', 'h3' ) ); ?>>
                        <?php if( true === get_theme_mod( 'enable_what_a_news_meta', true ) ) : ?>
                        <div class="newscope-post-meta mt-3">
                            <ul>
                                <?php
                                $whata_news_meta = get_theme_mod('main_what_a_news_meta');
                                $default_meta = array('author', 'date');
                                
                                // If no values are set, use the default values
                                if (empty($whata_news_meta) || !is_array($whata_news_meta)) {
                                    $whata_news_meta = $default_meta;
                                }

                                foreach( $whata_news_meta as $newscope_meta  ) : ?>
                                    <?php if( $newscope_meta == 'author'  ) : ?>
                                        <li><?php newscope_posted_by(); ?></li>
                                    <?php endif; ?>

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

                                    <?php if( $newscope_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                        <li class="comment-number"><?php newscope_comment_count(); ?></li>
                                    <?php endif; ?>
                                <?php  endforeach; ?>
                            </ul>
                        </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
        <?php elseif( 2 === $count) : ?>
        <div class="col-lg-4">
            <div class="news-blog-card v1 pb-4" data-aos="fade-left" data-aos-duration="800"
                data-aos-delay="100">
                <div class="news-blog-card-img <?php echo esc_attr( has_post_thumbnail() != true ? 'card-bg-color' : '' ); ?>">
                    <?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 class="news-blog-content position-absolate">
                        <?php if( true === get_theme_mod( 'enable_what_a_news_cat', true ) ){
                            echo '<div class="slider-cat">';
                            newscope_front_post_cat();
                            echo '</div>';
                        }?>
                        <<?php echo esc_attr( get_theme_mod( 'feature_title_tag', 'h3' ) ); ?> class="blog-title v2 title-font-size-20"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></<?php echo esc_attr( get_theme_mod( 'feature_title_tag', 'h3' ) ); ?>>
                        <?php if( true === get_theme_mod( 'enable_what_a_news_meta', true ) ) : ?>
                        <div class="newscope-post-meta mt-3">
                            <ul>
                                <?php
                                $whata_news_meta = get_theme_mod('main_what_a_news_meta');
                                $default_meta = array('author', 'date');
                                
                                // If no values are set, use the default values
                                if (empty($whata_news_meta) || !is_array($whata_news_meta)) {
                                    $whata_news_meta = $default_meta;
                                }

                                foreach( $whata_news_meta as $newscope_meta  ) : ?>
                                    <?php if( $newscope_meta == 'author'  ) : ?>
                                        <li><?php newscope_posted_by(); ?></li>
                                    <?php endif; ?>

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

                                    <?php if( $newscope_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                        <li class="comment-number"><?php newscope_comment_count(); ?></li>
                                    <?php endif; ?>
                                <?php  endforeach; ?>
                            </ul>
                        </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
        <?php else : ?>
        <div class="col-lg-4">
            <div class="news-blog-card <?php echo esc_attr( has_post_thumbnail() == true ? 'v2' : 'v3' ); ?>" data-aos="fade-right" data-aos-duration="800" data-aos-delay="100">
                <div class="news-blog-card-img <?php echo esc_attr( has_post_thumbnail() != true ? 'card-bg-color' : '' ); ?>">
                    <?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 class="news-blog-content v2 position-absolate">
                        <?php if( true === get_theme_mod( 'enable_what_a_news_cat', true ) ){
                            echo '<div class="slider-cat">';
                            newscope_front_post_cat();
                            echo '</div>';
                        }?>
                        <<?php echo esc_attr( get_theme_mod( 'feature_title_tag', 'h3' ) ); ?> class="blog-title v2 title-font-size-17"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></<?php echo esc_attr( get_theme_mod( 'feature_title_tag', 'h3' ) ); ?>>
                        <?php if( true === get_theme_mod( 'enable_what_a_news_meta', true ) ) : ?>
                        <div class="newscope-post-meta mt-3">
                            <ul>
                                <?php
                                $whata_news_meta = get_theme_mod('main_what_a_news_meta');
                                $default_meta = array('author', 'date');
                                
                                // If no values are set, use the default values
                                if (empty($whata_news_meta) || !is_array($whata_news_meta)) {
                                    $whata_news_meta = $default_meta;
                                }

                                foreach( $whata_news_meta as $newscope_meta  ) : ?>
                                    <?php if( $newscope_meta == 'author'  ) : ?>
                                        <li><?php newscope_posted_by(); ?></li>
                                    <?php endif; ?>

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

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



/**
*  Latest Post Section Loop Hook
*/
if ( ! function_exists( 'newscope_latest_post_section_loop' ) ) :
    function newscope_latest_post_section_loop(){
        // Get theme modifications
        $enable_filter = get_theme_mod('enable_latest_news_filter', true);
        $select_filter = get_theme_mod('latest_news_select_filter', 'one');
        $cat = get_theme_mod('latest_news_post_cat', '');
        $tag = get_theme_mod('latest_news_post_tag', '');
        $order_by = get_theme_mod('news_latest_post_postby');
        $order = get_theme_mod('news_latest_post_order');

        // Set up query arguments
        $args = array(
            'posts_per_page' => 3,
            'post_type' => 'post',
            'orderby' => $order_by,
            'order' => $order,
        );

        // Add taxonomy filter if enabled
        if ($enable_filter) {
            if ($select_filter === 'one' && !empty($cat)) {
                $args['tax_query'] = array(
                    array(
                        'taxonomy' => 'category',
                        'terms' => $cat,
                        'field' => 'term_id',
                    ),
                );
            } elseif ($select_filter === 'two' && !empty($tag)) {
                $args['tax_query'] = array(
                    array(
                        'taxonomy' => 'post_tag',
                        'terms' => $tag,
                        'field' => 'term_id',
                    ),
                );
            }
        }

        // Execute the query
        $p = new \WP_Query($args);
      ?>
        <div class="row align-items-end">
            <div class="col-lg-6">
                <div class="section-title">
                    <div class="section-title-wrapper">
                        <div class="section-title-wrap">
                            <<?php echo esc_attr( get_theme_mod( 'latest_news_section_title_tag', 'h2' ) ); ?> class="big-title latest-news-quick" data-aos="fade-right" data-aos-duration="800" data-aos-delay="100"><?php echo esc_html( get_theme_mod( 'latest_news_section_title', __('Latest News','newscope') ) ); ?></<?php echo esc_attr( get_theme_mod( 'latest_news_section_title_tag', 'h2' ) ); ?>>
                        </div>
                    </div>
                    <?php if( true === get_theme_mod( 'enable_latest_readmore', true ) ) : ?>
                    <a href="<?php echo esc_url( get_theme_mod( 'latest_news_btn_url' ) ); ?>" class="news-btn v3 button-all" data-aos="fade-right" data-aos-duration="800" data-aos-delay="100"><?php echo esc_html( get_theme_mod( 'latest_news_btn_text', __('Read More','newscope') ) ); ?></a>
                    <?php endif; ?>
                </div>
                <?php $count = 0; while ( $p->have_posts() ): $p->the_post(); $count++;  ?>
                <?php if( 1 == $count ) : ?>
                <div class="news-blog-card latest-news-first-item" data-aos="fade-right" data-aos-duration="800" data-aos-delay="100">
                    <div class="news-blog-card-img <?php echo esc_attr( has_post_thumbnail() != true ? 'card-bg-color' : '' ); ?>">
                        <?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 class="news-blog-content v3">
                            
                            <?php if( true === get_theme_mod( 'enable_latest_post_cat', true ) ){
                                echo '<div class="slider-cat">';
                                newscope_front_post_cat();
                                echo '</div>';
                            }?>
                            <?php if( true === get_theme_mod( 'enable_latest_post_title', true ) ) : ?>
                            <<?php echo esc_attr( get_theme_mod( 'latest_post_title_tag', 'h3' ) ); ?> class="blog-title  v2 title-font-size-20"><a href="<?php the_permalink(); ?>"><?php echo newscope_words_limit( get_the_title(), get_theme_mod( 'latest_post_title_lanth', 20 ) ); ?></a></<?php echo esc_attr( get_theme_mod( 'latest_post_title_tag', 'h3' ) ); ?>>
                            <?php endif; ?>
                            <?php if( true === get_theme_mod( 'enable_latest_post_meta', true ) ) : ?>
                            <div class="newscope-post-meta mt-3 latest-post-meta">
                                <ul>
                                    <?php
                                    $whata_news_meta = get_theme_mod('latest_post_meta');
                                    $default_meta = array('author', 'date');
                                    
                                    // If no values are set, use the default values
                                    if (empty($whata_news_meta) || !is_array($whata_news_meta)) {
                                        $whata_news_meta = $default_meta;
                                    }

                                    foreach( $whata_news_meta as $newscope_meta  ) : ?>
                                        <?php if( $newscope_meta == 'author'  ) : ?>
                                            <li><?php newscope_posted_by(); ?></li>
                                        <?php endif; ?>

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

                                        <?php if( $newscope_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                            <li class="comment-number"><?php newscope_comment_count(); ?></li>
                                        <?php endif; ?>
                                    <?php  endforeach; ?>
                                </ul>
                            </div>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
                <?php endif; endwhile; wp_reset_query(); ?>
            </div>
            <div class="col-lg-6">
            <?php $count = 0; while ( $p->have_posts() ): $p->the_post(); $count++;  ?>
                <?php if( 1 != $count ) : ?>
                <div class="news-blog-card latest-news-second <?php echo esc_attr( has_post_thumbnail() == true ? 'v4' : 'v3' ); ?>" data-aos="fade-left" data-aos-duration="800"
                    data-aos-delay="100">
                    <div class="news-blog-card-img <?php echo esc_attr( has_post_thumbnail() != true ? 'card-bg-color' : '' ); ?>">
                        <?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 class="news-blog-content v2 position-absolate">
                            <?php if( true === get_theme_mod( 'enable_latest_post_cat', true ) ){
                                echo '<div class="slider-cat">';
                                newscope_front_post_cat();
                                echo '</div>';
                            }?>
                            <?php if( true === get_theme_mod( 'enable_latest_post_title', true ) ) : ?>
                            <<?php echo esc_attr( get_theme_mod( 'latest_post_title_tag', 'h3' ) ); ?> class="blog-title  v2 title-font-size-20"><a href="<?php the_permalink(); ?>"><?php echo newscope_words_limit( get_the_title(), get_theme_mod( 'latest_post_title_lanth', 20 ) ); ?></a></<?php echo esc_attr( get_theme_mod( 'latest_post_title_tag', 'h3' ) ); ?>>
                            <?php endif; ?>
                            <?php if( true === get_theme_mod( 'enable_latest_post_meta', true ) ) : ?>
                            <div class="newscope-post-meta mt-3">
                                <ul>
                                    <?php
                                    $whata_news_meta = get_theme_mod('latest_post_meta');
                                    $default_meta = array('author', 'date');
                                    
                                    // If no values are set, use the default values
                                    if (empty($whata_news_meta) || !is_array($whata_news_meta)) {
                                        $whata_news_meta = $default_meta;
                                    }

                                    foreach( $whata_news_meta as $newscope_meta  ) : ?>
                                        <?php if( $newscope_meta == 'author'  ) : ?>
                                            <li><?php newscope_posted_by(); ?></li>
                                        <?php endif; ?>

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

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


/**
*  Featured Post Section Loop
*/
if ( ! function_exists( 'newscope_featured_post_loop' ) ) :
    function newscope_featured_post_loop(){

        // Get theme modifications
        $enable_filter = get_theme_mod('enable_featured_filter', true);
        $select_filter = get_theme_mod('featured_select_filter', 'one');
        $cat = get_theme_mod('main_feature_post_cat', '');
        $tag = get_theme_mod('main_featured_post_tag', '');
        $order_by = get_theme_mod('news_featured_postby');
        $order = get_theme_mod('news_featured_order');

        // Set up query arguments
        $args = array(
            'posts_per_page' => 4,
            'post_type' => 'post',
            'orderby' => $order_by,
            'order' => $order,
        );

        // Add taxonomy filter if enabled
        if ($enable_filter) {
            if ($select_filter === 'one' && !empty($cat)) {
                $args['tax_query'] = array(
                    array(
                        'taxonomy' => 'category',
                        'terms' => $cat,
                        'field' => 'term_id',
                    ),
                );
            } elseif ($select_filter === 'two' && !empty($tag)) {
                $args['tax_query'] = array(
                    array(
                        'taxonomy' => 'post_tag',
                        'terms' => $tag,
                        'field' => 'term_id',
                    ),
                );
            }
        }
        $p = new WP_Query($args);
        $count = 0;
        ?>
        
        <?php while ($p->have_posts()): $p->the_post(); $count++; ?>
        
            <?php if ($count == 1): ?>
                <div class="health-news-left-img aos-init aos-animate" data-aos="fade-right" data-aos-duration="800" data-aos-delay="100">
                    <?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 class="news-blog-content position-absolate">
                            <?php if( true === get_theme_mod( 'enable_featured_cat', true ) ){
                                echo '<div class="slider-cat">';
                                newscope_front_post_cat();
                                echo '</div>';
                            }?>
        
                        <?php if (true === get_theme_mod('enable_featured_title', true)): ?>
                            <<?php echo esc_attr(get_theme_mod('feature_title_tag', 'h3')); ?> class="blog-title v2 title-font-size-36">
                                <a href="<?php the_permalink(); ?>"><?php echo newscope_words_limit(get_the_title(), get_theme_mod('featured_post_title_lanth', 20)); ?></a>
                            </<?php echo esc_attr(get_theme_mod('feature_title_tag', 'h3')); ?>>
                        <?php endif; ?>
                        <?php if( true === get_theme_mod( 'enable_featured_meta', true ) ) : ?>
                            <div class="newscope-post-meta mt-3">
                                <ul>
                                    <?php
                                    $whata_news_meta = get_theme_mod('latest_post_meta');
                                    $default_meta = array('author', 'date');
                                    
                                    // If no values are set, use the default values
                                    if (empty($whata_news_meta) || !is_array($whata_news_meta)) {
                                        $whata_news_meta = $default_meta;
                                    }

                                    foreach( $whata_news_meta as $newscope_meta  ) : ?>
                                        <?php if( $newscope_meta == 'author'  ) : ?>
                                            <li><?php newscope_posted_by(); ?></li>
                                        <?php endif; ?>

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

                                        <?php if( $newscope_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                            <li class="comment-number"><?php newscope_comment_count(); ?></li>
                                        <?php endif; ?>
                                    <?php  endforeach; ?>
                                </ul>
                            </div>
                            <?php endif; ?>
                    </div>
                </div>
        
            <?php else: ?>
                <?php if ($count == 2): ?>
                    <div class="feature-posts-right-content">
                <?php endif; ?>
        
                <?php if ($count == 2): ?>
                    <div class="news-right-top-img aos-init aos-animate" data-aos="fade-left" data-aos-duration="800" data-aos-delay="100">
                        <?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 class="news-blog-content position-absolate">
                            <?php if( true === get_theme_mod( 'enable_featured_cat', true ) ){
                                echo '<div class="slider-cat">';
                                newscope_front_post_cat();
                                echo '</div>';
                            }?>
        
                            <?php if (true === get_theme_mod('enable_featured_title', true)): ?>
                                <<?php echo esc_attr(get_theme_mod('feature_title_tag', 'h3')); ?> class="blog-title v2 title-font-size-36">
                                    <a href="<?php the_permalink(); ?>"><?php echo newscope_words_limit(get_the_title(), get_theme_mod('featured_post_title_lanth', 20)); ?></a>
                                </<?php echo esc_attr(get_theme_mod('feature_title_tag', 'h3')); ?>>
                            <?php endif; ?>
        
                            <?php if( true === get_theme_mod( 'enable_featured_meta', true ) ) : ?>
                            <div class="newscope-post-meta mt-3">
                                <ul>
                                    <?php
                                    $whata_news_meta = get_theme_mod('latest_post_meta');
                                    $default_meta = array('author', 'date');
                                    
                                    // If no values are set, use the default values
                                    if (empty($whata_news_meta) || !is_array($whata_news_meta)) {
                                        $whata_news_meta = $default_meta;
                                    }

                                    foreach( $whata_news_meta as $newscope_meta  ) : ?>
                                        <?php if( $newscope_meta == 'author'  ) : ?>
                                            <li><?php newscope_posted_by(); ?></li>
                                        <?php endif; ?>

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

                                        <?php if( $newscope_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                            <li class="comment-number"><?php newscope_comment_count(); ?></li>
                                        <?php endif; ?>
                                    <?php  endforeach; ?>
                                </ul>
                            </div>
                            <?php endif; ?>
                        </div>
                    </div>
                <?php else : ?>
                    <div class="feature-news-card <?php echo esc_attr( $count == 4 ? 'v2' : '' ); ?> aos-init aos-animate" data-aos="fade-left" data-aos-duration="800" data-aos-delay="100">
                        <?php if (has_post_thumbnail()): ?>    
                        <div class="news-card-img">
                            <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); ?>">
                        </div>
                        <?php endif; ?>
                        <div class="news-blog-content">
                            <?php if( true === get_theme_mod( 'enable_featured_cat', true ) ){
                                echo '<div class="slider-cat">';
                                newscope_front_post_cat();
                                echo '</div>';
                            }?>
                            <?php if (true === get_theme_mod('enable_featured_title', true)): ?>
                                <<?php echo esc_attr(get_theme_mod('feature_title_tag', 'h3')); ?> class="blog-title v2 title-font-size-30">
                                    <a href="<?php the_permalink(); ?>"><?php echo newscope_words_limit(get_the_title(), get_theme_mod('featured_post_title_lanth', 20)); ?></a>
                                </<?php echo esc_attr(get_theme_mod('feature_title_tag', 'h3')); ?>>
                            <?php endif; ?>
        
                            <div class="news-blog-footer">
                            <?php if( true === get_theme_mod( 'enable_featured_meta', true ) ) : ?>
                            <div class="newscope-post-meta mt-3">
                                <ul>
                                    <?php
                                    $whata_news_meta = get_theme_mod('latest_post_meta');
                                    $default_meta = array('author', 'date');
                                    
                                    // If no values are set, use the default values
                                    if (empty($whata_news_meta) || !is_array($whata_news_meta)) {
                                        $whata_news_meta = $default_meta;
                                    }

                                    foreach( $whata_news_meta as $newscope_meta  ) : ?>
                                        <?php if( $newscope_meta == 'author'  ) : ?>
                                            <li><?php newscope_posted_by(); ?></li>
                                        <?php endif; ?>

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

                                        <?php if( $newscope_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                            <li class="comment-number"><?php newscope_comment_count(); ?></li>
                                        <?php endif; ?>
                                    <?php  endforeach; ?>
                                </ul>
                            </div>
                            <?php endif; ?>
                                <div class="footer-icon">
                                    <a href="<?php the_permalink(); ?>">
                                        <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/image/feature-posts/arrow-icon.svg" alt="">
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endif; ?>
        
                <?php if ( $count == 4): ?>
                    </div> 
                <?php endif; ?>
        
            <?php endif; ?>
        
        <?php endwhile; wp_reset_query(); ?>
        <?php 
    }
endif;
add_action( 'newscope_featured_post_loop_action', 'newscope_featured_post_loop' );/**



*  Weekend TOp Post Section Loop
*/
if ( ! function_exists( 'newscope_weekend_top_post_loop' ) ) :
    function newscope_weekend_top_post_loop(){

        // Get theme modifications
        $enable_filter = get_theme_mod('enable_weekend_top_news_filter', true);
        $select_filter = get_theme_mod('weekend_top_news_select_filter', 'one');
        $display = get_theme_mod('dispaly_weekend_top_news_items', 4);
        $cat = get_theme_mod('weekend_top_news_post_cat', '');
        $tag = get_theme_mod('weekend_top_news_post_tag', '');
        $order = get_theme_mod('weekend_top_news_order');
        $order_by = get_theme_mod('weekend_top_news_postby');

        // Set up query arguments
        $args = array(
            'posts_per_page' => $display,
            'post_type' => 'post',
            'orderby' => $order_by,
            'order' => $order,
        );

        // Add taxonomy filter if enabled
        if ($enable_filter) {
            if ($select_filter === 'one' && !empty($cat)) {
                $args['tax_query'] = array(
                    array(
                        'taxonomy' => 'category',
                        'terms' => $cat,
                        'field' => 'term_id',
                    ),
                );
            } elseif ($select_filter === 'two' && !empty($tag)) {
                $args['tax_query'] = array(
                    array(
                        'taxonomy' => 'post_tag',
                        'terms' => $tag,
                        'field' => 'term_id',
                    ),
                );
            }
        }
        $p = new WP_Query($args);
        $count = 0;
        $lastOddIndex = -1;
        $lastEvenIndex = -1;
        
        // First, loop through the posts to determine the last odd and even indexes
        while ($p->have_posts()): $p->the_post();
            $count++;
            if ($count % 2 !== 0) {
                $lastOddIndex = $count;
            } else {
                $lastEvenIndex = $count;
            }
        endwhile;
        
        // Reset post data to run the loop again for rendering
        wp_reset_postdata();
        
        $count = 0;
        ?>
        
        <?php while ($p->have_posts()): $p->the_post(); $count++; ?>
            <?php
            $classes = 'col-lg-6';
            if ($count % 2 !== 0) {
                $classes .= ' odd';
                if ($count === $lastOddIndex) {
                    $classes .= ' last-odd';
                }
            } else {
                $classes .= ' even';
                if ($count === $lastEvenIndex) {
                    $classes .= ' last-even';
                }
            }
            ?>
            <div class="<?php echo esc_attr($classes); ?>">
                <div class="weekend-card" data-aos="fade-right" data-aos-duration="800" data-aos-delay="100">
                    <div class="news-blog-content v3">
                        <?php if (true === get_theme_mod('enable_weekend_top_news_cat', true)) {
                            echo '<div class="slider-cat">';
                            newscope_front_post_cat();
                            echo '</div>';
                        }?>
                        <?php if (true === get_theme_mod('enable_weekend_top_news_title', true)): ?>
                            <<?php echo esc_attr(get_theme_mod('weekend_top_news_title_tag', 'h2')); ?> class="blog-title  v2 title-font-size-30">
                                <a href="<?php the_permalink(); ?>"><?php echo newscope_words_limit(get_the_title(), get_theme_mod('featured_post_title_lanth', 20)); ?></a>
                            </<?php echo esc_attr(get_theme_mod('weekend_top_news_title_tag', 'h2')); ?>>
                        <?php endif; ?>
                        
                        <?php if (true === get_theme_mod('enable_weekend_top_news_meta', true)): ?>
                        <div class="newscope-post-meta mt-3 latest-post-meta">
                            <ul>
                                <?php
                                $whata_news_meta = get_theme_mod('weekend_top_news_meta');
                                $default_meta = array('author', 'date');
                                
                                // If no values are set, use the default values
                                if (empty($whata_news_meta) || !is_array($whata_news_meta)) {
                                    $whata_news_meta = $default_meta;
                                }
        
                                foreach ($whata_news_meta as $newscope_meta): ?>
                                    <?php if ($newscope_meta == 'author'): ?>
                                        <li><?php newscope_posted_by(); ?></li>
                                    <?php endif; ?>
        
                                    <?php if ($newscope_meta == 'date'): ?>
                                        <li><?php newscope_posted_on(); ?></li>
                                    <?php endif; ?>
        
                                    <?php if ($newscope_meta == 'comment' && get_comments_number() != 0): ?>
                                        <li class="comment-number"><?php newscope_comment_count(); ?></li>
                                    <?php endif; ?>
                                <?php endforeach; ?>
                            </ul>
                        </div>
                        <?php endif; ?>
                    </div>
                    <div class="card-wrapper">
                        <div class="card-icon">
                            <a href="<?php the_permalink(); ?>">
                                <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/image/feature-posts/weekend-arrow-icon.svg">
                            </a>
                        </div>
                        <?php if (has_post_thumbnail()): ?>    
                            <div class="weekend-img">
                                <a href="<?php the_permalink(); ?>">
                                    <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); ?>">
                                </a>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        <?php endwhile; wp_reset_query(); ?>
        <?php 
    }
endif;
add_action( 'newscope_weekend_top_post_loop_action', 'newscope_weekend_top_post_loop' );


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

            // Check if the 'web-stories' plugin is active
        if (is_plugin_active('web-stories/web-stories.php')) {
            $post_type = get_theme_mod('stories_post_type', 'post') === 'web-story' ? 'web-story' : 'post';
        } else {
            $post_type = 'post';
        }

        // Initialize default WP_Query arguments
        $query_args = array(
            'posts_per_page' => 8,
            'post_type'      => $post_type,
            'orderby'        => get_theme_mod('stories_post_postby'),
            'order'          => get_theme_mod('stories_post_postby'),
        );

        // Modify query arguments based on theme modifications
        if ($post_type === 'web-story' && true === get_theme_mod('enable_stories_story_filter') && !empty(get_theme_mod('stories_story_filter_cat', ''))) {
            $query_args['tax_query'] = array(
                array(
                    'taxonomy' => 'web_story_category',
                    'terms'    => get_theme_mod('stories_story_filter_cat'),
                    'field'    => 'term_id',
                ),
            );
        } elseif ($post_type === 'post' && true === get_theme_mod('enable_stories_filter', true)) {
            $stories_select_filter = get_theme_mod('stories_select_filter', 'one');

            if ('one' === $stories_select_filter && !empty(get_theme_mod('main_stories_post_cat', ''))) {
                $query_args['tax_query'] = array(
                    array(
                        'taxonomy' => 'category',
                        'terms'    => get_theme_mod('main_stories_post_cat'),
                        'field'    => 'term_id',
                    ),
                );
            } elseif ('two' === $stories_select_filter && !empty(get_theme_mod('main_stories_post_tag', ''))) {
                $query_args['tax_query'] = array(
                    array(
                        'taxonomy' => 'post_tag',
                        'terms'    => get_theme_mod('main_stories_post_tag'),
                        'field'    => 'term_id',
                    ),
                );
            }
        }

    // Execute the query
    $p = new WP_Query($query_args);
        ?>
        <?php while ( $p->have_posts() ): $p->the_post(); ?>
            <?php if( has_post_thumbnail() ) : ?>
            <div class="swiper-slide">
                <div class="tranding-stories-card">
                    <?php if ( true === get_theme_mod('enable_stories_title', true)): ?>
                        <<?php echo esc_attr(get_theme_mod('stories_title_tag', 'h2')); ?> class="stories-card-title">
                            <a href="<?php the_permalink(); ?>"><?php echo newscope_words_limit(get_the_title(), get_theme_mod('main_stories_title_lanth', 20)); ?></a>
                        </<?php echo esc_attr(get_theme_mod('stories_title_tag', 'h2')); ?>>
                    <?php endif; ?>
                    <?php if (has_post_thumbnail()): ?>    
                        <div class="stories-card-img">
                            <a href="<?php the_permalink(); ?>">
                                <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); ?>">
                            </a>
                        </div>
                    <?php endif; ?>
                    <div class="stories-card-icon">
                        <a href="<?php the_permalink( ); ?>">
                            <img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/image/trending-stories/story-arrow-icon.svg" alt="arrow-icon">
                        </a>
                    </div>
                </div>
            </div>
            <?php endif; ?>
        <?php endwhile; wp_reset_query(); ?>
        <?php 
    }
endif;
add_action( 'newscope_stories_post_loop_action', 'newscope_stories_post_loop' );


/**
*  Most Popular Post Section Loop
*/
if ( ! function_exists( 'newscope_most_popular_post_loop' ) ) :
    function newscope_most_popular_post_loop(){

        // Get theme modifications
        $enable_filter = get_theme_mod('enable_most_popular_news_filter', true);
        $select_filter = get_theme_mod('most_popular_news_select_filter', 'one');
        $cat = get_theme_mod('most_popular_news_post_cat', '');
        $tag = get_theme_mod('most_popular_news_post_tag', '');
        $order = get_theme_mod('news_most_popular_post_order');
        $order_by = get_theme_mod('news_most_popular_post_postby');

        // Set up query arguments
        $args = array(
            'posts_per_page' => 4,
            'post_type' => 'post',
            'orderby' => $order_by,
            'order' => $order,
        );

        // Add taxonomy filter if enabled
        if ($enable_filter) {
            if ($select_filter === 'one' && !empty($cat)) {
                $args['tax_query'] = array(
                    array(
                        'taxonomy' => 'category',
                        'terms' => $cat,
                        'field' => 'term_id',
                    ),
                );
            } elseif ($select_filter === 'two' && !empty($tag)) {
                $args['tax_query'] = array(
                    array(
                        'taxonomy' => 'post_tag',
                        'terms' => $tag,
                        'field' => 'term_id',
                    ),
                );
            }
        }
        $p = new WP_Query($args);
        $count = 0;
        while ($p->have_posts()): $p->the_post(); $count++;
        if ($count == 1):
       ?>
        <div class="col-lg-8">
            <div class="most-popular-left-content" data-aos="fade-right" data-aos-duration="800"
                data-aos-delay="100">
                <?php if (has_post_thumbnail()): ?>
                    <div class="most-popular-left-img">
                        <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); ?>">
                    </div>
                <?php endif; ?>

                <div class="news-blog-content">
                    <?php if( true === get_theme_mod( 'enable_most_popular_cat', true ) ){
                        echo '<div class="slider-cat">';
                        newscope_front_post_cat();
                        echo '</div>';
                    }?>
                    <?php if (true === get_theme_mod('enable_most_popular_post_title', true)): ?>
                        <<?php echo esc_attr(get_theme_mod('most_popular_post_title_tag', 'h3')); ?> class="blog-title title-font-size-30">
                            <a href="<?php the_permalink(); ?>"><?php echo newscope_words_limit(get_the_title(), get_theme_mod('most_popular_post_title_lanth', 20)); ?></a>
                        </<?php echo esc_attr(get_theme_mod('most_popular_post_title_tag', 'h3')); ?>>
                    <?php endif; ?>
                    
                    <?php if( true === get_theme_mod( 'enable_most_popular_post_meta', true ) ) : ?>
                    <div class="newscope-post-meta mt-3 latest-post-meta">
                        <ul>
                            <?php
                            $whata_news_meta = get_theme_mod('most_popular_post_meta');
                            $default_meta = array('author', 'date');
                            
                            // If no values are set, use the default values
                            if (empty($whata_news_meta) || !is_array($whata_news_meta)) {
                                $whata_news_meta = $default_meta;
                            }

                            foreach( $whata_news_meta as $newscope_meta  ) : ?>
                                <?php if( $newscope_meta == 'author'  ) : ?>
                                    <li><?php newscope_posted_by(); ?></li>
                                <?php endif; ?>

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

                                <?php if( $newscope_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                    <li class="comment-number"><?php newscope_comment_count(); ?></li>
                                <?php endif; ?>
                            <?php  endforeach; ?>
                        </ul>
                    </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        <?php else: ?>
            <?php if ($count == 2): ?>
            <div class="col-lg-4">
                <div class="most-popular-right-content">
                    <ul class="most-popular-list">
            <?php endif; ?>
                        <li>
                            <div class="most-popular-card text-center" data-aos="fade-left" data-aos-duration="800"
                                data-aos-delay="100">
                                <?php if (has_post_thumbnail()): ?>
                                    <div class="popular-card-img">
                                        <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); ?>">
                                    </div>
                                <?php endif; ?>
                                <div class="card-wrapper">
                                <?php if( true === get_theme_mod( 'enable_most_popular_cat', true ) ){
                                    echo '<div class="popular-tag">';
                                    newscope_front_post_cat();
                                    echo '</div>';
                                }?>
                                    <?php if (true === get_theme_mod('enable_most_popular_post_title', true)): ?>
                                        <<?php echo esc_attr(get_theme_mod('most_popular_post_title_tag', 'h3')); ?> class="popular-title">
                                            <a href="<?php the_permalink(); ?>"><?php echo newscope_words_limit(get_the_title(), get_theme_mod('most_popular_post_title_lanth', 20)); ?></a>
                                        </<?php echo esc_attr(get_theme_mod('most_popular_post_title_tag', 'h3')); ?>>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </li>
                        <?php if ( $count == 4): ?>
                    </ul>
                </div>
            </div>
        <?php endif; endif; ?>
        <?php endwhile; wp_reset_query(); ?>
        <?php 
    }
endif;
add_action( 'newscope_most_popular_post_loop_action', 'newscope_most_popular_post_loop' );



/**
*  What A News Section Loop Hook
*/
if ( ! function_exists( 'newscope_tranding_post_loop' ) ) :
    function newscope_tranding_post_loop(){

        // Get theme modifications
        $enable_filter = get_theme_mod('enable_tranding_post_filter', true);
        $select_filter = get_theme_mod('tranding_post_select_filter', 'one');
        $cat = get_theme_mod('tranding_post_post_cat', '');
        $tag = get_theme_mod('tranding_post_post_tag', '');
        $posts_per_page = get_theme_mod('tranding_post_display', 4 );
        $order_by = get_theme_mod('news_tranding_post_postby');
        $order = get_theme_mod('news_tranding_post_order');

        // Set up query arguments
        $args = array(
            'posts_per_page' => $posts_per_page,
            'post_type' => 'post',
            'orderby' => $order_by,
            'order' => $order,
        );

        // Add taxonomy filter if enabled
        if ($enable_filter) {
            if ($select_filter === 'one' && !empty($cat)) {
                $args['tax_query'] = array(
                    array(
                        'taxonomy' => 'category',
                        'terms' => $cat,
                        'field' => 'term_id',
                    ),
                );
            } elseif ($select_filter === 'two' && !empty($tag)) {
                $args['tax_query'] = array(
                    array(
                        'taxonomy' => 'post_tag',
                        'terms' => $tag,
                        'field' => 'term_id',
                    ),
                );
            }
        }

        // Execute the query
        $p = new \WP_Query($args);
        ?>
        <div class="trending-posts-wrapper">
            <div class="swiper trending-posts-swiper2">
                <div class="swiper-wrapper">
                    <?php  while ($p->have_posts()): $p->the_post(); if (has_post_thumbnail()) : ?>
                    <div class="swiper-slide">
                        <div class="trending-post-card" style="background-image: url(<?php echo get_the_post_thumbnail_url(get_the_ID(), 'full'); ?>);">
                            <div class="news-blog-content">
                                <?php if( true === get_theme_mod( 'enable_most_popular_cat', true ) ){
                                    echo '<div class="slider-cat">';
                                    newscope_front_post_cat();
                                    echo '</div>';
                                }?>
                                <?php if (true === get_theme_mod('enable_tranding_post_title', true)): ?>
                                    <<?php echo esc_attr(get_theme_mod('tranding_post_title_tag', 'h3')); ?> class="blog-title v1">
                                        <a href="<?php the_permalink(); ?>"><?php echo newscope_words_limit(get_the_title(), get_theme_mod('tranding_post_title_lanth', 20)); ?></a>
                                    </<?php echo esc_attr(get_theme_mod('tranding_post_title_tag', 'h3')); ?>>
                                <?php endif; ?>
                                <?php if( true === get_theme_mod( 'enable_tranding_post_meta', true ) ) : ?>
                                <div class="newscope-post-meta mt-3 latest-post-meta tranding-post-meta">
                                    <ul>
                                        <?php
                                        $whata_news_meta = get_theme_mod('tranding_post_meta');
                                        $default_meta = array('author', 'date');
                                        
                                        // If no values are set, use the default values
                                        if (empty($whata_news_meta) || !is_array($whata_news_meta)) {
                                            $whata_news_meta = $default_meta;
                                        }

                                        foreach( $whata_news_meta as $newscope_meta  ) : ?>
                                            <?php if( $newscope_meta == 'author'  ) : ?>
                                                <li><?php newscope_posted_by(); ?></li>
                                            <?php endif; ?>

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

                                            <?php if( $newscope_meta == 'comment' && get_comments_number() != 0 ) : ?>
                                                <li class="comment-number"><?php newscope_comment_count(); ?></li>
                                            <?php endif; ?>
                                        <?php  endforeach; ?>
                                    </ul>
                                </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                    <?php endif; endwhile; wp_reset_query(); ?>
                </div>
                <div class="trending-posts-swiper-button">
                    <div class="swiper-button-next"><?php echo esc_html__( 'Next','newscope' ); ?></div>
                    <div class="swiper-button-prev"><?php echo esc_html__( 'Prev','newscope' ); ?></div>
                </div>
            </div>
            <div class="swiper trending-posts-swiper tranding-post-dot">
                <div class="swiper-wrapper">
                    <?php  while ($p->have_posts()): $p->the_post(); ?>
                        <?php if (has_post_thumbnail()) : ?>
                        <div class="swiper-slide">
                            <div class="post-mini-img">
                                <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); ?>">
                            </div>
                        </div>
                        <?php endif; ?>
                    <?php endwhile; wp_reset_query(); ?>
                </div>
            </div>
        </div>
        <?php 
    }
endif;
add_action( 'newscope_tranding_post_loop_action', 'newscope_tranding_post_loop' );


/**
*  What A News Section Loop Hook
*/
if ( ! function_exists( 'newscope_category_section_loop' ) ) :
    function newscope_category_section_loop(){
        ?>
        <div class="category-news-wrapper">
            <?php
            // Number of categories to display
            $categories_per_page = get_theme_mod( 'category_post_display', 20 );

            // Arguments for get_categories
            $args = array(
                'orderby' => get_theme_mod( 'category_section_postby', 'rand' ),  // Order by name
                'order' => get_theme_mod( 'category_section_order', 'ASC' ),     // Order ascending
                'number' => $categories_per_page, // Number of categories to display
                'hide_empty' => true, // Show empty categories
            );

            // Get the categories
            $categories = get_categories($args);

            // Animation classes array
            $animation_classes = [
                'fade-right', 'fade-up-right', 'fade-down-left', 'fade-down', 'fade-up',
                'fade-down', 'fade-down-left', 'fade-down', 'fade-down-right', 'fade-up',
                'fade-up-right', 'fade-down', 'fade-up-left', 'fade-down', 'fade-up'
            ];

            $index = 0;
            foreach ($categories as $category) {
                $count = $category->count;
                $name = $category->name;
                $link = get_category_link($category->term_id);
                $color = get_category_color($category->term_id); // Get the color for the category
                $animation_class = $animation_classes[$index % count($animation_classes)];
                $index++;
                ?>
                <a href="<?php echo esc_url($link); ?>" class="news-tag-category-btn" data-aos="<?php echo esc_attr($animation_class); ?>" data-aos-duration="800" data-aos-delay="100" style="background-color: <?php echo esc_attr($color); ?>;">
                    <?php echo esc_html($name); ?> <span><?php echo esc_html($count); ?></span>
                </a>
                <?php
            }
            ?>
        </div>
        <?php 
    }
endif;
add_action( 'newscope_category_section_action', 'newscope_category_section_loop' );