I have a section in a page template in the theme I'm making that displays content based on a page the user selects in the customizer using the dropdown-pages control. Right now it's just using the standard default refresh transport, but since that's kind of clunky reloading the whole iframe, I was wondering if it was possible to use the new selective refresh feature. But I'm not sure how to implement it. Anyone know if this is possible and if so how to do it?
Here is the code in my page template that displays the content:
<?php if ((get_theme_mod( 'intro_page' )) != '') {
$intro_id = get_theme_mod( 'intro_page' );
$intro_header = get_the_title( $intro_id );
$intro_excerpt = get_the_excerpt( $intro_id );
$intro_link = get_the_permalink( $intro_id );
$intro_linktext = get_post_meta( $intro_id, 'emm_cta_text', true );
echo '<h1>' . esc_html($intro_header) . '</h1>' . '<p>' . esc_html($intro_excerpt) . '</p>';
if( ! get_post_meta( $intro_id, 'emm_cta_text', true ) ) {
echo '<p><a class="cta" href="' . esc_url($intro_link) . '">Learn More</a></p>';
}else{
echo '<p><a class="cta" href="' . esc_url($intro_link) . '">' . esc_html($intro_linktext) . '</a></p>';
}
} ?>
Here is the code for the setting in customizer:
$wp_customize->add_setting( 'intro_page' , array(
'sanitize_callback' => 'absint',
) );
$wp_customize->add_control( 'intro_page', array(
'label' => __( 'Page to use for intro section', 'veritas' ),
'section' => 'intro',
'settings' => 'intro_page',
'type' => 'dropdown-pages',
'priority' => 1
) );