        <?php
        /**
         * nino Theme Customizer
         *
         * @package nino
         */

        /**
         * Add postMessage support for site title and description for the Theme Customizer.
         *
         * @param WP_Customize_Manager $wp_customize Theme Customizer object.
         */
        function nino_customize_register( $wp_customize ) {
            // Enable live preview for site title and description.
            $wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
            $wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
            $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';

            // Add selective refresh support.
            if ( isset( $wp_customize->selective_refresh ) ) {
                $wp_customize->selective_refresh->add_partial( 'blogname', array(
                    'selector'        => '.site-title a',
                    'render_callback' => 'nino_customize_partial_blogname',
                ));

                $wp_customize->selective_refresh->add_partial( 'blogdescription', array(
                    'selector'        => '.site-description',
                    'render_callback' => 'nino_customize_partial_blogdescription',
                ));
            }

            // Footer Settings Section
            $wp_customize->add_section( 'nino_footer_section', array(
                'title'    => __( 'Footer Settings', 'nino' ),
                'priority' => 130,
            ));

            // Footer copyright text setting.
            $wp_customize->add_setting( 'nino_footer_copyright', array(
                'default'           => '',
                'sanitize_callback' => 'sanitize_text_field',
            ));

            // Footer copyright text control.
            $wp_customize->add_control( 'nino_footer_copyright', array(
                'label'    => __( 'Copyright Text', 'nino' ),
                'section'  => 'nino_footer_section',
                'type'     => 'text',
            ));

            // Blog Layout Section
            $wp_customize->add_section( 'nino_layout_sec', array(
                'title'       => __( 'Blog Layout', 'nino' ),
                'description' => __( 'Choose your preferred blog layout.', 'nino' ),
            ));

            // Blog layout setting.
            $wp_customize->add_setting( 'nino_layout_set', array(
                'default'           => 'grid',
                'type'              => 'theme_mod',
                'sanitize_callback' => 'sanitize_key',
            ));

            // Blog layout control.
            $wp_customize->add_control( 'nino_ctrl_layout', array(
                'label'    => __( 'Select Layout', 'nino' ),
                'section'  => 'nino_layout_sec',
                'settings' => 'nino_layout_set',
                'type'     => 'radio',
                'choices'  => array(
                    'classic' => __( 'Classic', 'nino' ),
                    'grid'    => __( 'Grid', 'nino' ),
                ),
            ));


          // Add a section for category settings if not already added
$wp_customize->add_section('post_category_settings', array(
    'title'    => __('Post Category Settings', 'nino'),
    'priority' => 30,
));

// Add a checkbox setting to enable/disable featured posts
$wp_customize->add_setting('nino_enable_featured_post', array(
    'default'           => true, // Default to enabled
    'sanitize_callback' => 'rest_sanitize_boolean', // Sanitize as boolean
));

// Add a checkbox control for enabling/disabling featured posts
$wp_customize->add_control('nino_enable_featured_post', array(
    'label'    => __('Enable Featured Post Section', 'nino'),
    'section'  => 'post_category_settings',
    'type'     => 'checkbox',
));

// Add the category dropdown setting if not already added
$wp_customize->add_setting('nino_selected_post_category', array(
    'default'           => '',
    'sanitize_callback' => 'absint', // Ensure the category ID is an integer
));

$categories = get_categories(array('hide_empty' => false));
$choices = array();
foreach ($categories as $category) {
    $choices[$category->term_id] = $category->name;
}

// Add a control for selecting the post category
$wp_customize->add_control('nino_selected_post_category', array(
    'label'    => __('Select a Post Category', 'nino'),
    'section'  => 'post_category_settings',
    'type'     => 'select',
    'choices'  => $choices,
));

// Add a custom title setting
$wp_customize->add_setting('nino_custom_category_title', array(
    'default'           => '', // Default to empty
    'sanitize_callback' => 'sanitize_text_field', // Sanitize as plain text
));

// Add a control for the custom category title
$wp_customize->add_control('nino_custom_category_title', array(
    'label'       => __('Custom Category Title', 'nino'),
    'section'     => 'post_category_settings',
    'type'        => 'text',
    'description' => __('Enter a custom title for the category. If empty, the selected category name will be used.', 'nino'),
));

        }
        add_action( 'customize_register', 'nino_customize_register' );

        /**
         * Render the site title for the selective refresh partial.
         */
        function nino_customize_partial_blogname() {
            bloginfo( 'name' );
        }

        /**
         * Render the site tagline for the selective refresh partial.
         */
        function nino_customize_partial_blogdescription() {
            bloginfo( 'description' );
        }

        /**
         * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
         */
        function nino_customize_preview_js() {
            wp_enqueue_script( 'nino-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), _S_VERSION, true );
        }
        add_action( 'customize_preview_init', 'nino_customize_preview_js' );
