add_section( 'benpress_section_blog', array( 'title' => esc_html__( 'Blog Settings', 'benpress' ), 'priority' => 20, 'panel' => 'benpress_options_panel', ) ); // Add Blog Title setting and control. $wp_customize->add_setting( 'benpress_theme_options[blog_title]', array( 'default' => '', 'type' => 'option', 'transport' => 'postMessage', 'sanitize_callback' => 'wp_kses_post', ) ); $wp_customize->add_control( 'benpress_theme_options[blog_title]', array( 'label' => esc_html__( 'Blog Title', 'benpress' ), 'section' => 'benpress_section_blog', 'settings' => 'benpress_theme_options[blog_title]', 'type' => 'text', 'priority' => 10, ) ); $wp_customize->selective_refresh->add_partial( 'benpress_theme_options[blog_title]', array( 'selector' => '.blog-header .blog-title', 'render_callback' => 'benpress_customize_partial_blog_title', 'fallback_refresh' => false, ) ); // Add Blog Description setting and control. $wp_customize->add_setting( 'benpress_theme_options[blog_description]', array( 'default' => '', 'type' => 'option', 'transport' => 'postMessage', 'sanitize_callback' => 'wp_kses_post', ) ); $wp_customize->add_control( 'benpress_theme_options[blog_description]', array( 'label' => esc_html__( 'Blog Description', 'benpress' ), 'section' => 'benpress_section_blog', 'settings' => 'benpress_theme_options[blog_description]', 'type' => 'textarea', 'priority' => 20, ) ); $wp_customize->selective_refresh->add_partial( 'benpress_theme_options[blog_description]', array( 'selector' => '.blog-header .blog-description', 'render_callback' => 'benpress_customize_partial_blog_description', 'fallback_refresh' => false, ) ); // Add Settings and Controls for blog layout. $wp_customize->add_setting( 'benpress_theme_options[blog_layout]', array( 'default' => 'excerpt', 'type' => 'option', 'transport' => 'postMessage', 'sanitize_callback' => 'benpress_sanitize_select', ) ); $wp_customize->add_control( 'benpress_theme_options[blog_layout]', array( 'label' => esc_html__( 'Blog Layout', 'benpress' ), 'section' => 'benpress_section_blog', 'settings' => 'benpress_theme_options[blog_layout]', 'type' => 'radio', 'priority' => 30, 'choices' => array( 'index' => esc_html__( 'Display full posts', 'benpress' ), 'excerpt' => esc_html__( 'Display post excerpts', 'benpress' ), ), ) ); // Add Setting and Control for Excerpt Length. $wp_customize->add_setting( 'benpress_theme_options[excerpt_length]', array( 'default' => 35, 'type' => 'option', 'transport' => 'postMessage', 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( 'benpress_theme_options[excerpt_length]', array( 'label' => esc_html__( 'Excerpt Length', 'benpress' ), 'section' => 'benpress_section_blog', 'settings' => 'benpress_theme_options[excerpt_length]', 'type' => 'text', 'priority' => 40, ) ); // Add Partial for Blog Layout and Excerpt Length. $wp_customize->selective_refresh->add_partial( 'benpress_blog_layout_partial', array( 'selector' => '.site-main .post-wrapper', 'settings' => array( 'benpress_theme_options[blog_layout]', 'benpress_theme_options[excerpt_length]', ), 'render_callback' => 'benpress_customize_partial_blog_layout', 'fallback_refresh' => false, ) ); // Add Setting and Control for Read More Text. $wp_customize->add_setting( 'benpress_theme_options[read_more_text]', array( 'default' => esc_html__( 'Continue reading', 'benpress' ), 'type' => 'option', 'transport' => 'postMessage', 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'benpress_theme_options[read_more_text]', array( 'label' => esc_html__( 'Read More Text', 'benpress' ), 'section' => 'benpress_section_blog', 'settings' => 'benpress_theme_options[read_more_text]', 'type' => 'text', 'priority' => 50, ) ); // Add Magazine Widgets Headline. $wp_customize->add_control( new benpress_Customize_Header_Control( $wp_customize, 'benpress_theme_options[blog_magazine_widgets_title]', array( 'label' => esc_html__( 'Magazine Widgets', 'benpress' ), 'section' => 'benpress_section_blog', 'settings' => array(), 'priority' => 60, ) ) ); // Add Setting and Control for showing post date. $wp_customize->add_setting( 'benpress_theme_options[blog_magazine_widgets]', array( 'default' => true, 'type' => 'option', 'transport' => 'refresh', 'sanitize_callback' => 'benpress_sanitize_checkbox', ) ); $wp_customize->add_control( 'benpress_theme_options[blog_magazine_widgets]', array( 'label' => esc_html__( 'Display Magazine widgets on blog index', 'benpress' ), 'section' => 'benpress_section_blog', 'settings' => 'benpress_theme_options[blog_magazine_widgets]', 'type' => 'checkbox', 'priority' => 70, ) ); } add_action( 'customize_register', 'benpress_customize_register_blog_settings' ); /** * Render the blog title for the selective refresh partial. */ function benpress_customize_partial_blog_title() { echo wp_kses_post( benpress_get_option( 'blog_title' ) ); } /** * Render the blog description for the selective refresh partial. */ function benpress_customize_partial_blog_description() { echo wp_kses_post( benpress_get_option( 'blog_description' ) ); } /** * Render the blog layout for the selective refresh partial. */ function benpress_customize_partial_blog_layout() { while ( have_posts() ) { the_post(); get_template_part( 'template-parts/content', esc_attr( benpress_get_option( 'blog_layout' ) ) ); } }