<?php
/**
 * Custom Functions.
 *
 * @package Digital Media
 */

if( !function_exists( 'digital_media_fonts_url' ) ) :

    //Google Fonts URL
    function digital_media_fonts_url(){

        $font_families = array(
            'Plus+Jakarta+Sans:ital,wght@0,200..800;1,200..800', //    font-family: "Plus Jakarta Sans", sans-serif;
        );

        $fonts_url = add_query_arg( array(
            'family' => implode( '&family=', $font_families ),
            'display' => 'swap',
        ), 'https://fonts.googleapis.com/css2' );

        return esc_url_raw($fonts_url);

    }

endif;

if ( ! function_exists( 'digital_media_sub_menu_toggle_button' ) ) :

    function digital_media_sub_menu_toggle_button( $args, $item, $depth ) {

        // Add sub menu toggles to the main menu with toggles
        if ( $args->theme_location == 'digital-media-primary-menu' && isset( $args->show_toggles ) ) {
            
            // Wrap the menu item link contents in a div, used for positioning
            $args->before = '<div class="submenu-wrapper">';
            $args->after  = '';

            // Add a toggle to items with children
            if ( in_array( 'menu-item-has-children', $item->classes ) ) {

                $toggle_target_string = '.menu-item.menu-item-' . $item->ID . ' > .sub-menu';

                // Add the sub menu toggle
                $args->after .= '<button type="button" class="theme-aria-button submenu-toggle" data-toggle-target="' . $toggle_target_string . '" data-toggle-type="slidetoggle" data-toggle-duration="250" aria-expanded="false"><span class="btn__content" tabindex="-1"><span class="screen-reader-text">' . esc_html__( 'Show sub menu', 'digital-media' ) . '</span>' . digital_media_get_theme_svg( 'chevron-down' ) . '</span></button>';

            }

            // Close the wrapper
            $args->after .= '</div><!-- .submenu-wrapper -->';
            // Add sub menu icons to the main menu without toggles (the fallback menu)

        }elseif( $args->theme_location == 'digital-media-primary-menu' ) {

            if ( in_array( 'menu-item-has-children', $item->classes ) ) {

                $args->before = '<div class="link-icon-wrapper">';
                $args->after  = digital_media_get_theme_svg( 'chevron-down' ) . '</div>';

            } else {

                $args->before = '';
                $args->after  = '';

            }

        }

        return $args;

    }

endif;

add_filter( 'nav_menu_item_args', 'digital_media_sub_menu_toggle_button', 10, 3 );

if ( ! function_exists( 'digital_media_the_theme_svg' ) ):
    
    function digital_media_the_theme_svg( $digital_media_svg_name, $return = false ) {

        if( $return ){

            return digital_media_get_theme_svg( $digital_media_svg_name ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in digital_media_get_theme_svg();.

        }else{

            echo digital_media_get_theme_svg( $digital_media_svg_name ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in digital_media_get_theme_svg();.

        }
    }

endif;

if ( ! function_exists( 'digital_media_get_theme_svg' ) ):

    function digital_media_get_theme_svg( $digital_media_svg_name ) {

        // Make sure that only our allowed tags and attributes are included.
        $digital_media_svg = wp_kses(
            Digital_Media_SVG_Icons::get_svg( $digital_media_svg_name ),
            array(
                'svg'     => array(
                    'class'       => true,
                    'xmlns'       => true,
                    'width'       => true,
                    'height'      => true,
                    'viewbox'     => true,
                    'aria-hidden' => true,
                    'role'        => true,
                    'focusable'   => true,
                ),
                'path'    => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'd'         => true,
                    'transform' => true,
                ),
                'polygon' => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'points'    => true,
                    'transform' => true,
                    'focusable' => true,
                ),
                'polyline' => array(
                    'fill'      => true,
                    'points'    => true,
                ),
                'line' => array(
                    'fill'      => true,
                    'x1'      => true,
                    'x2' => true,
                    'y1'    => true,
                    'y2' => true,
                ),
            )
        );
        if ( ! $digital_media_svg ) {
            return false;
        }
        return $digital_media_svg;

    }

endif;

if( !function_exists( 'digital_media_post_category_list' ) ) :

    // Post Category List.
    function digital_media_post_category_list( $select_cat = true ){

        $post_cat_lists = get_categories(
            array(
                'hide_empty' => '0',
                'exclude' => '1',
            )
        );

        $post_cat_cat_array = array();
        if( $select_cat ){

            $post_cat_cat_array[''] = esc_html__( '-- Select Category --','digital-media' );

        }

        foreach ( $post_cat_lists as $post_cat_list ) {

            $post_cat_cat_array[$post_cat_list->slug] = $post_cat_list->name;

        }

        return $post_cat_cat_array;
    }

endif;

if( !function_exists('digital_media_single_post_navigation') ):

    function digital_media_single_post_navigation(){

        $digital_media_default = digital_media_get_default_theme_options();
        $twp_navigation_type = esc_attr( get_post_meta( get_the_ID(), 'twp_disable_ajax_load_next_post', true ) );
        $current_id = '';
        $article_wrap_class = '';
        global $post;
        $current_id = $post->ID;
        if( $twp_navigation_type == '' || $twp_navigation_type == 'global-layout' ){
            $twp_navigation_type = get_theme_mod('twp_navigation_type', $digital_media_default['twp_navigation_type']);
        }

        if( $twp_navigation_type != 'no-navigation' && 'post' === get_post_type() ){

            if( $twp_navigation_type == 'theme-normal-navigation' ){ ?>

                <div class="navigation-wrapper">
                    <?php
                    // Previous/next post navigation.
                    the_post_navigation(array(
                        'prev_text' => '<span class="arrow" aria-hidden="true">' . digital_media_the_theme_svg('arrow-left',$return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Previous post:', 'digital-media') . '</span><span class="post-title">%title</span>',
                        'next_text' => '<span class="arrow" aria-hidden="true">' . digital_media_the_theme_svg('arrow-right',$return = true ) . '</span><span class="screen-reader-text">' . esc_html__('Next post:', 'digital-media') . '</span><span class="post-title">%title</span>',
                    )); ?>
                </div>
                <?php

            }else{

                $next_post = get_next_post();
                if( isset( $next_post->ID ) ){

                    $next_post_id = $next_post->ID;
                    echo '<div loop-count="1" next-post="' . absint( $next_post_id ) . '" class="twp-single-infinity"></div>';

                }
            }

        }

    }

endif;

add_action( 'digital_media_navigation_action','digital_media_single_post_navigation',30 );

if( !function_exists('digital_media_content_offcanvas') ):

    // Offcanvas Contents
    function digital_media_content_offcanvas(){ ?>

        <div id="offcanvas-menu">
            <div class="offcanvas-wraper">
                <div class="close-offcanvas-menu">
                    <div class="offcanvas-close">
                        <a href="javascript:void(0)" class="skip-link-menu-start"></a>
                        <button type="button" class="button-offcanvas-close">
                            <span class="offcanvas-close-label">
                                <?php echo esc_html__('Close', 'digital-media'); ?>
                            </span>
                        </button>
                    </div>
                </div>
                <div id="primary-nav-offcanvas" class="offcanvas-item offcanvas-main-navigation">
                    <nav class="primary-menu-wrapper" aria-label="<?php esc_attr_e('Horizontal', 'digital-media'); ?>" role="navigation">
                        <ul class="primary-menu theme-menu">
                            <?php
                            if (has_nav_menu('digital-media-primary-menu')) {
                                wp_nav_menu(
                                    array(
                                        'container' => '',
                                        'items_wrap' => '%3$s',
                                        'theme_location' => 'digital-media-primary-menu',
                                        'show_toggles' => true,
                                    )
                                );
                            }else{

                                wp_list_pages(
                                    array(
                                        'match_menu_classes' => true,
                                        'show_sub_menu_icons' => true,
                                        'title_li' => false,
                                        'show_toggles' => true,
                                        'walker' => new Digital_Media_Walker_Page(),
                                    )
                                );
                            }
                            ?>
                        </ul>
                    </nav><!-- .primary-menu-wrapper -->
                </div>
                <a href="javascript:void(0)" class="skip-link-menu-end"></a>
            </div>
        </div>

    <?php
    }

endif;

add_action( 'digital_media_before_footer_content_action','digital_media_content_offcanvas',30 );

if( !function_exists('digital_media_footer_content_widget') ):

    function digital_media_footer_content_widget(){
        
        $digital_media_default = digital_media_get_default_theme_options();
        
        $digital_media_footer_column_layout = absint(get_theme_mod('digital_media_footer_column_layout', $digital_media_default['digital_media_footer_column_layout']));
        $digital_media_footer_sidebar_class = 12;
        
        if($digital_media_footer_column_layout == 2) {
            $digital_media_footer_sidebar_class = 6;
        }
        
        if($digital_media_footer_column_layout == 3) {
            $digital_media_footer_sidebar_class = 4;
        }
        ?>
        
        <?php if ( get_theme_mod('digital_media_display_footer', true) == true ) : ?>
            <div class="footer-widgetarea">
                <div class="wrapper">
                    <div class="column-row">
                    
                        <?php for ($i = 0; $i < $digital_media_footer_column_layout; $i++) : ?>
                            
                            <div class="column <?php echo 'column-' . absint($digital_media_footer_sidebar_class); ?> column-sm-12">
                                
                                <?php 
                                // If no widgets are assigned, display default widgets
                                if ( ! is_active_sidebar( 'digital-media-footer-widget-' . $i ) ) : 

                                    if ($i === 0) : ?>
                                        <div id="media_image-3" class="widget widget_media_image">
                                            <img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/logo.png'); ?>" alt="<?php echo esc_attr__( 'Footer Image', 'digital-media' ); ?>" style="max-width: 100%; height: auto;">
                                        </div>
                                        <div id="text-3" class="widget widget_text">
                                            <div class="textwidget">
                                                <p class="widget_text">
                                                    <?php esc_html_e('The Digital Media WordPress Theme is a sophisticated and dynamic theme specifically designed for digital marketing agencies and professionals. Built to cater to a wide range of digital marketing services, this theme is ideal for showcasing services such as SEO, PPC, social media marketing, and content marketing.', 'digital-media'); ?>
                                                </p>
                                            </div>
                                        </div>

                                    <?php elseif ($i === 1) : ?>
                                        <div id="pages-2" class="widget widget_pages">
                                            <h2 class="widget-title"><?php esc_html_e('Calendar', 'digital-media'); ?></h2>
                                            <?php get_calendar(); ?>
                                        </div>

                                    <?php elseif ($i === 2) : ?>
                                        <div id="search-2" class="widget widget_search">
                                            <h2 class="widget-title"><?php esc_html_e('Enter Keywords Here', 'digital-media'); ?></h2>
                                            <?php get_search_form(); ?>
                                        </div>
                                    <?php endif; 
                                    
                                else :
                                    // Display dynamic sidebar widget if assigned
                                    dynamic_sidebar('digital-media-footer-widget-' . $i);
                                endif;
                                ?>
                                
                            </div>
                            
                        <?php endfor; ?>

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

    <?php
    }

endif;

add_action( 'digital_media_footer_content_action', 'digital_media_footer_content_widget', 10 );

if( !function_exists('digital_media_footer_content_info') ):

    /**
     * Footer Copyright Area
    **/
    function digital_media_footer_content_info(){

        $digital_media_default = digital_media_get_default_theme_options(); ?>
        <div class="site-info">
            <div class="wrapper">
                <div class="column-row">
                    <div class="column column-9">
                        <div class="footer-credits">
                            <div class="footer-copyright">
                                <?php
                                    $digital_media_footer_copyright_text = wp_kses_post( get_theme_mod( 'digital_media_footer_copyright_text', $digital_media_default['digital_media_footer_copyright_text'] ) );
                                        echo esc_html( $digital_media_footer_copyright_text );
                                        echo '<br>';
                                        echo esc_html__('Theme: ', 'digital-media') . '<a href="' . esc_url('https://www.omegathemes.com/products/free-marketing-wordpress-theme') . '" title="' . esc_attr__('DIGITAL MEDIA', 'digital-media') . '" target="_blank"><span>' . esc_html__('DIGITAL MEDIA', 'digital-media') . '</span></a>' . esc_html__(' By ', 'digital-media') . '  <span>' . esc_html__('OMEGA ', 'digital-media') . '</span>';
                                        echo esc_html__('Powered by ', 'digital-media') . '<a href="' . esc_url('https://wordpress.org') . '" title="' . esc_attr__('WordPress', 'digital-media') . '" target="_blank"><span>' . esc_html__('WordPress.', 'digital-media') . '</span></a>';
                                    ?>
                            </div>
                        </div>
                    </div>
                    <div class="column column-3 align-text-right">
                        <a class="to-the-top" href="#site-header">
                            <span class="to-the-top-long">
                                <?php if ( get_theme_mod('digital_media_enable_to_the_top', true) == true ) : ?>
                                    <?php
                                    $digital_media_to_the_top_text = get_theme_mod( 'digital_media_to_the_top_text', __( 'To the Top', 'digital-media' ) );
                                    printf( 
                                        wp_kses( 
                                            /* translators: %s is the arrow icon markup */
                                            '%s %s', 
                                            array( 'span' => array( 'class' => array(), 'aria-hidden' => array() ) ) 
                                        ), 
                                        esc_html( $digital_media_to_the_top_text ),
                                        '<span class="arrow" aria-hidden="true">&uarr;</span>' 
                                    );
                                    ?>
                                <?php endif; ?>
                            </span>
                        </a>
                    </div>
                </div>
            </div>
        </div>

    <?php
    }

endif;

add_action( 'digital_media_footer_content_action','digital_media_footer_content_info',20 );


if ( ! function_exists( 'digital_media_main_slider' ) ) :

    function digital_media_main_slider() {
        $output = '';
        $digital_media_defaults = digital_media_get_default_theme_options();
        $digital_media_header_slider = get_theme_mod( 'digital_media_header_slider', $digital_media_defaults['digital_media_header_slider'] );

        // Debugging header slider status
        if ( ! $digital_media_header_slider ) {
            error_log('Header slider is not enabled or has a falsy value.');
            return '';  // Exit early if no slider
        }

        $digital_media_banner_background_image = get_theme_mod( 'digital_media_banner_background_image', $digital_media_defaults['digital_media_banner_background_image'] );
        $digital_media_header_banner_cat = get_theme_mod( 'digital_media_header_banner_cat');

        $digital_media_header_phone_number = esc_html( get_theme_mod( 'digital_media_header_phone_number',
        $digital_media_defaults['digital_media_header_phone_number'] ) );

        $digital_media_header_email_id = esc_html( get_theme_mod( 'digital_media_header_email_id',
        $digital_media_defaults['digital_media_header_email_id'] ) );

        $digital_media_header_location = esc_html( get_theme_mod( 'digital_media_header_location',
        $digital_media_defaults['digital_media_header_location'] ) );

        $banner_query = new WP_Query( array(
            'post_type' => 'post',
            'posts_per_page' => 4,
            'post__not_in' => get_option( 'sticky_posts' ),
            'category_name' => esc_html( $digital_media_header_banner_cat ),
        ) );

        // Check if the query has posts
        if ( ! $banner_query->have_posts() ) {
            error_log('No posts found for the banner query.');
            return '';  // Exit early if no posts
        }

        ob_start();  // Start output buffering
        ?>
        <div id="site-content" class="main-banner">
            <div class="slider-box" style="background: url(<?php echo esc_url( $digital_media_banner_background_image ); ?>);">
                <div class="main-slider">
                    <div class="swiper-container theme-main-carousel">
                        <div class="swiper-wrapper">
                            <?php while ( $banner_query->have_posts() ) : $banner_query->the_post();
                                $digital_media_featured_image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' )[0] ?? get_template_directory_uri() . '/inc/homepage-setup/assets/homepage-setup-images/slider-img1.png';
                                ?>
                                <div class="swiper-slide main-carousel-item">
                                    <div class="slider-main">
                                        <div class="left-box">
                                            <div class="slide-heading-main">
                                                <div class="main-carousel-caption">
                                                    <div class="post-content">
                                                        <header class="entry-header">
                                                            <h2 class="slider-heading">
                                                                <a href="<?php the_permalink(); ?>" rel="bookmark"><span><?php echo esc_html( get_the_title() ); ?></span></a>
                                                            </h2>
                                                        </header>
                                                        <div class="entry-content">
                                                            <?php
                                                            if ( has_excerpt() ) {
                                                                echo esc_html( get_the_excerpt() );
                                                            } else {
                                                                echo esc_html( wp_trim_words( get_the_content(), 25, '...' ) );
                                                            }
                                                            ?>
                                                        </div>
                                                        <div class="slide-btn">
                                                            <a href="<?php the_permalink(); ?>" class="btn-fancy btn-fancy-primary">
                                                                <?php echo esc_html__( 'Get Started Now', 'digital-media' ); ?>
                                                            </a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="right-box">
                                            <div class="image-main-box">
                                                <div class="data-bg banner-img" data-background="<?php echo esc_url( $digital_media_featured_image ); ?>">
                                                    <a href="<?php the_permalink(); ?>" class="theme-image-responsive"></a>
                                                </div>
                                                <?php digital_media_post_format_icon(); ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php endwhile; ?>
                        </div>
                        <div class="swiper-pagination"></div>
                    </div>
                </div>
            </div>
            <div class=" header-wrapper sldier-contact-box">
                <?php if( $digital_media_header_phone_number ){ ?>
                    <div class="theme-header-areas header-areas-right header-button">
                        <div class="phone-icon">
                            <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512" aria-hidden="true">
                                <path d="M497.4 361.8l-112-48a24 24 0 0 0 -28 6.9l-49.6 60.6A370.7 370.7 0 0 1 130.6 204.1l60.6-49.6a23.9 23.9 0 0 0 6.9-28l-48-112A24.2 24.2 0 0 0 122.6 .6l-104 24A24 24 0 0 0 0 48c0 256.5 207.9 464 464 464a24 24 0 0 0 23.4-18.6l24-104a24.3 24.3 0 0 0 -14-27.6z"/>
                            </svg>
                        </div>
                        <div class="phone-text">
                            <p class="default-text"><?php echo esc_html( 'Got Questions?', 'digital-media'); ?></p>
                            <p><a href="tel:<?php echo esc_html( $digital_media_header_phone_number ); ?>"><?php echo esc_html( $digital_media_header_phone_number ); ?></a></p>
                        </div>
                    </div>
                <?php } ?>
                    
                <?php if( $digital_media_header_email_id ){ ?>
                    <div class="theme-header-areas header-areas-right header-button">
                        <div class="phone-icon">
                            <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512" aria-hidden="true">
                                <path d="M502.3 190.8c3.9-3.1 9.7-.2 9.7 4.7V400c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V195.6c0-5 5.7-7.8 9.7-4.7 22.4 17.4 52.1 39.5 154.1 113.6 21.1 15.4 56.7 47.8 92.2 47.6 35.7 .3 72-32.8 92.3-47.6 102-74.1 131.6-96.3 154-113.7zM256 320c23.2 .4 56.6-29.2 73.4-41.4 132.7-96.3 142.8-104.7 173.4-128.7 5.8-4.5 9.2-11.5 9.2-18.9v-19c0-26.5-21.5-48-48-48H48C21.5 64 0 85.5 0 112v19c0 7.4 3.4 14.3 9.2 18.9 30.6 23.9 40.7 32.4 173.4 128.7 16.8 12.2 50.2 41.8 73.4 41.4z"/>
                            </svg>
                        </div>
                        <div class="phone-text">
                            <p class="default-text"><?php echo esc_html( 'Email Us', 'digital-media'); ?></p>
                            <p><a href="mailto:<?php echo esc_html( $digital_media_header_email_id ); ?>"><?php echo esc_html( $digital_media_header_email_id ); ?></a></p>
                        </div>
                    </div>
                <?php } ?>

                <?php if( $digital_media_header_location ){ ?>
                    <div class="theme-header-areas header-areas-right header-button">
                        <div class="phone-icon">
                            <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 384 512" aria-hidden="true">
                                <path d="M172.3 501.7C27 291 0 269.4 0 192 0 86 86 0 192 0s192 86 192 192c0 77.4-27 99-172.3 309.7-9.5 13.8-29.9 13.8-39.5 0zM192 272c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80z"/>
                            </svg>
                        </div>
                        <div class="phone-text">
                            <p class="default-text"><?php echo esc_html( 'Address', 'digital-media'); ?></p>
                            <p><?php echo esc_html( $digital_media_header_location ); ?></p>
                        </div>
                    </div>
                <?php } ?>
            </div>
        </div>
        <?php
        wp_reset_postdata();
        $output = ob_get_clean(); // Get buffered output and clean buffer
        return $output; // Return the output instead of echoing
    }

endif;



if( !function_exists( 'digital_media_product_section' ) ) :

    function digital_media_product_section(){ 

        $digital_media_default = digital_media_get_default_theme_options();

        $digital_media_header_case_studies = get_theme_mod( 'digital_media_header_case_studies', $digital_media_default['digital_media_header_case_studies'] );
        $digital_media_locations_post_cat = get_theme_mod( 'digital_media_locations_post_cat' );

        $digital_media_team_section_subtitle = esc_html( get_theme_mod( 'digital_media_team_section_subtitle',
        $digital_media_default['digital_media_team_section_subtitle'] ) );

        $digital_media_team_section_title = esc_html( get_theme_mod( 'digital_media_team_section_title',
        $digital_media_default['digital_media_team_section_title'] ) );

        $digital_media_locations_query = new WP_Query( array('post_type' => 'post', 'posts_per_page' => 6,'post__not_in' => get_option("sticky_posts"), 'category_name' => esc_html( $digital_media_locations_post_cat ) ) );

            if( $digital_media_locations_query->have_posts() ): 
            if( $digital_media_header_case_studies ){
            ?>
            
                <div class="theme-product-block">
                    <div class="wrapper">
                        <div class="section-heading">
                            <?php if( $digital_media_team_section_subtitle ){ ?>
                                <h6><?php echo esc_html( $digital_media_team_section_subtitle ); ?> <span><?php echo esc_html( $digital_media_team_section_subtitle ); ?></span></h6>
                            <?php } ?>
                            <?php if( $digital_media_team_section_title ){ ?>
                                <h4><?php echo esc_html( $digital_media_team_section_title ); ?></h4>
                            <?php } ?>
                        </div>
                        <div class="tab-box">
                            <!-- Tab Header -->
                            <div class="tab-header">
                                <?php
                                for ($i = 1; $i <= 4; $i++) {
                                    $digital_media_tab_title = get_theme_mod('digital_media_price_list_tab_title' . $i);
                                    if ($digital_media_tab_title) {
                                        echo '<div class="tab-item ' . (($i == 1) ? 'active' : '') . '" onclick="showTabContent(' . $i . ')">' . esc_html($digital_media_tab_title) . '</div>';
                                    }
                                }
                                ?>
                            </div>
                            <!-- Tab Content -->
                            <?php if( get_theme_mod('digital_media_category_tab1','Web Design')  || get_theme_mod('digital_media_category_tab2','uncategorized') || get_theme_mod('digital_media_category_tab3','Web Design') || get_theme_mod('digital_media_category_tab4') ) { ?>
                            <div class="tabcontent">
                                <?php

                                // Separate post query outside the tab content loop
                                $digital_media_header_pricing_plans_cats = array(
                                    get_theme_mod('digital_media_category_tab1','Web Design'),
                                    get_theme_mod('digital_media_category_tab2','uncategorized'),
                                    get_theme_mod('digital_media_category_tab3','Web Design'),
                                    get_theme_mod('digital_media_category_tab4')
                                );

                                for ($i = 1; $i <= 4; $i++) {
                                    $category_slug = esc_html($digital_media_header_pricing_plans_cats[$i - 1]);

                                    $digital_media_tab_banner_query = new WP_Query(array(
                                        'post_type' => 'post',
                                        'posts_per_page' => 2,
                                        'post__not_in' => get_option("sticky_posts"),
                                        'category_name' => $category_slug
                                    ));

                                    if ($digital_media_tab_banner_query->have_posts()) :
                                        echo '<div class="tab-content" id="tab-content-' . $i . '">'; ?>
                                        <div class="post-main-content"> 
                                            <?php
                                $s=1;
                                while( $digital_media_tab_banner_query->have_posts() ):
                                $digital_media_tab_banner_query->the_post();
                                $digital_media_featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
                                $digital_media_featured_image = isset( $digital_media_featured_image[0] ) ? $digital_media_featured_image[0] : ''; 

                                $digital_media_team_section_designation = esc_html( get_theme_mod( 'digital_media_team_section_designation'.$s ) );

                                ?>                                
                                <div class="theme-article-post slider-post-content">
                                    <div class="entry-thumbnail">
                                        <div class="data-bg featured-img" data-background="<?php echo esc_url($digital_media_featured_image ? $digital_media_featured_image : get_template_directory_uri() . '/inc/homepage-setup/assets/homepage-setup-images/slider-img1.png'); ?>">
                                            <a href="<?php the_permalink(); ?>" class="theme-image-responsive" tabindex="0"></a>
                                        </div>
                                        <?php digital_media_post_format_icon(); ?>
                                    </div>
                                    <div class="main-owl-caption">
                                        <div class="post-content-location">
                                            <span class="slide-cat">
                                                <?php 
                                                $categories = get_the_category();
                                                if ( ! empty( $categories ) ) {
                                                    echo esc_html( $categories[0]->name ); // Display the first category name
                                                }
                                                ?>
                                            </span>
                                            <header class="entry-header">
                                                <?php if( $digital_media_team_section_designation ){ ?>
                                                    <p><?php echo esc_html( $digital_media_team_section_designation ); ?></p>
                                                <?php } ?>
                                                <h2 class="entry-title entry-title-big">
                                                    <a href="<?php the_permalink(); ?>" rel="bookmark"><span><?php the_title(); ?></span></a>
                                                </h2> 
                                                <a class="banner-btn" href="<?php the_permalink(); ?>"><?php echo esc_html('View Case Study +','digital-media'); ?></a>
                                            </header>
                                        </div>
                                    </div>
                                </div>
                            <?php $s++; endwhile; 
                                        echo '</div>';
                                        echo '</div>';
                                        wp_reset_postdata();
                                    endif;
                                } ?>
                            </div>
                            <?php } ?>
                        </div>
                    </div>
                </div>
            <?php } ?>
             <?php
            wp_reset_postdata();
            endif;
          ?>
    <?php }

endif;

if (!function_exists('digital_media_post_format_icon')):

    // Post Format Icon.
    function digital_media_post_format_icon() {

        $digital_media_format = get_post_format(get_the_ID()) ?: 'standard';
        $digital_media_icon = '';
        $digital_media_title = '';
        if( $digital_media_format == 'video' ){
            $digital_media_icon = digital_media_get_theme_svg( 'video' );
            $digital_media_title = esc_html__('Video','digital-media');
        }elseif( $digital_media_format == 'audio' ){
            $digital_media_icon = digital_media_get_theme_svg( 'audio' );
            $digital_media_title = esc_html__('Audio','digital-media');
        }elseif( $digital_media_format == 'gallery' ){
            $digital_media_icon = digital_media_get_theme_svg( 'gallery' );
            $digital_media_title = esc_html__('Gallery','digital-media');
        }elseif( $digital_media_format == 'quote' ){
            $digital_media_icon = digital_media_get_theme_svg( 'quote' );
            $digital_media_title = esc_html__('Quote','digital-media');
        }elseif( $digital_media_format == 'image' ){
            $digital_media_icon = digital_media_get_theme_svg( 'image' );
            $digital_media_title = esc_html__('Image','digital-media');
        } elseif( $digital_media_format == 'link' ){
            $digital_media_icon = digital_media_get_theme_svg( 'link' );
            $digital_media_title = esc_html__('Link','digital-media');
        } elseif( $digital_media_format == 'status' ){
            $digital_media_icon = digital_media_get_theme_svg( 'status' );
            $digital_media_title = esc_html__('Status','digital-media');
        } elseif( $digital_media_format == 'aside' ){
            $digital_media_icon = digital_media_get_theme_svg( 'aside' );
            $digital_media_title = esc_html__('Aside','digital-media');
        } elseif( $digital_media_format == 'chat' ){
            $digital_media_icon = digital_media_get_theme_svg( 'chat' );
            $digital_media_title = esc_html__('Chat','digital-media');
        }
        
        if (!empty($digital_media_icon)) { ?>
            <div class="theme-post-format">
                <span class="post-format-icom"><?php echo digital_media_svg_escape($digital_media_icon); ?></span>
                <?php if( $digital_media_title ){ echo '<span class="post-format-label">'.esc_html( $digital_media_title ).'</span>'; } ?>
            </div>
        <?php }
    }

endif;

if ( ! function_exists( 'digital_media_svg_escape' ) ):

    /**
     * Get information about the SVG icon.
     *
     * @param string $digital_media_svg_name The name of the icon.
     * @param string $group The group the icon belongs to.
     * @param string $color Color code.
     */
    function digital_media_svg_escape( $digital_media_input ) {

        // Make sure that only our allowed tags and attributes are included.
        $digital_media_svg = wp_kses(
            $digital_media_input,
            array(
                'svg'     => array(
                    'class'       => true,
                    'xmlns'       => true,
                    'width'       => true,
                    'height'      => true,
                    'viewbox'     => true,
                    'aria-hidden' => true,
                    'role'        => true,
                    'focusable'   => true,
                ),
                'path'    => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'd'         => true,
                    'transform' => true,
                ),
                'polygon' => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'points'    => true,
                    'transform' => true,
                    'focusable' => true,
                ),
            )
        );

        if ( ! $digital_media_svg ) {
            return false;
        }

        return $digital_media_svg;

    }

endif;

if( !function_exists( 'digital_media_sanitize_sidebar_option_meta' ) ) :

    // Sidebar Option Sanitize.
    function digital_media_sanitize_sidebar_option_meta( $digital_media_input ){

        $metabox_options = array( 'global-sidebar','left-sidebar','right-sidebar','no-sidebar' );
        if( in_array( $digital_media_input,$metabox_options ) ){

            return $digital_media_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'digital_media_sanitize_pagination_meta' ) ) :

    // Sidebar Option Sanitize.
    function digital_media_sanitize_pagination_meta( $digital_media_input ){

        $digital_media_metabox_options = array( 'Center','Right','Left');
        if( in_array( $digital_media_input,$digital_media_metabox_options ) ){

            return $digital_media_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'digital_media_sanitize_pagination_type' ) ) :

    /**
     * Sanitize the pagination type setting.
     *
     * @param string $digital_media_input The input value from the Customizer.
     * @return string The sanitized value.
     */
    function digital_media_sanitize_pagination_type( $digital_media_input ) {
        // Define valid options for the pagination type.
        $digital_media_valid_options = array( 'numeric', 'newer_older' ); // Update valid options to include 'newer_older'

        // If the input is one of the valid options, return it. Otherwise, return the default option ('numeric').
        if ( in_array( $digital_media_input, $digital_media_valid_options, true ) ) {
            return $digital_media_input;
        } else {
            // Return 'numeric' as the fallback if the input is invalid.
            return 'numeric';
        }
    }

endif;

// Sanitize the enable/disable setting for pagination
if( !function_exists('digital_media_sanitize_enable_pagination') ) :
    function digital_media_sanitize_enable_pagination( $digital_media_input ) {
        return (bool) $digital_media_input;
    }
endif;

if( !function_exists( 'digital_media_sanitize_menu_transform' ) ) :

    // Sidebar Option Sanitize.
    function digital_media_sanitize_menu_transform( $digital_media_input ){

        $digital_media_metabox_options = array( 'capitalize','uppercase','lowercase');
        if( in_array( $digital_media_input,$digital_media_metabox_options ) ){

            return $digital_media_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'digital_media_sanitize_page_content_alignment' ) ) :

    // Sidebar Option Sanitize.
    function digital_media_sanitize_page_content_alignment( $digital_media_input ){

        $digital_media_metabox_options = array( 'left','center','right');
        if( in_array( $digital_media_input,$digital_media_metabox_options ) ){

            return $digital_media_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'digital_media_sanitize_footer_widget_title_alignment' ) ) :

    // Footer Option Sanitize.
    function digital_media_sanitize_footer_widget_title_alignment( $digital_media_input ){

        $digital_media_metabox_options = array( 'left','center','right');
        if( in_array( $digital_media_input,$digital_media_metabox_options ) ){

            return $digital_media_input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'digital_media_sanitize_copyright_alignment_meta' ) ) :

    // Sidebar Option Sanitize.
    function digital_media_sanitize_copyright_alignment_meta( $digital_media_input ){

        $digital_media_metabox_options = array( 'Default','Reverse','Center');
        if( in_array( $digital_media_input,$digital_media_metabox_options ) ){

            return $digital_media_input;

        }else{

            return '';

        }
    }

endif;

/**
 * Sidebar Layout Function
 */
function digital_media_get_final_sidebar_layout() {
	$digital_media_defaults       = digital_media_get_default_theme_options();
	$digital_media_global_layout  = get_theme_mod('digital_media_global_sidebar_layout', $digital_media_defaults['digital_media_global_sidebar_layout']);
	$digital_media_page_layout    = get_theme_mod('digital_media_page_sidebar_layout', $digital_media_global_layout);
	$digital_media_post_layout    = get_theme_mod('digital_media_post_sidebar_layout', $digital_media_global_layout);
	$digital_media_meta_layout    = get_post_meta(get_the_ID(), 'digital_media_post_sidebar_option', true);

	if (!empty($digital_media_meta_layout) && $digital_media_meta_layout !== 'default') {
		return $digital_media_meta_layout;
	}
	if (is_page() || (function_exists('is_shop') && is_shop())) {
		return $digital_media_page_layout;
	}
	if (is_single()) {
		return $digital_media_post_layout;
	}
	return $digital_media_global_layout;
}