Skip to navigation
Wordpress customizer multiselect as custom customizer
29.09.19
$wp_customize->add_setting('show_on_page', array( 'default' => '1' )); $wp_customize->add_control( new Multiple_Select( $wp_customize, 'multiple_select_setting', array( 'label' => __('page1', 'dd_theme'), 'section' => 'footer_bg', 'settings' => 'show_on_page', 'type' => 'select', 'type' => 'multiple-select', // The $type in our class 'choices' => array( 'google' => 'Google', 'bing' => 'Bing' ) // Your choices ) ) ); } class Multiple_Select extends WP_Customize_Control { public $type = 'multiple-select'; public function render_content() { if ( empty( $this->choices ) ): return; endif; ?>
label ); ?>
link(); ?> multiple="multiple" style="height: 100%;"> choices as $value => $label ) { $selected = ( in_array( $value, $this->value() ) ) ? selected( 1, 1, false ) : ''; echo '
' . $label . '
'; } ?>
https://jayj.dk/multiple-select-lists-theme-customizer/
Reply
Anonymous
to get the list of all pages and make a multi select: $p = array(); foreach (get_pages() as $page_data): $p[$page_data->ID] = $page_data->post_title; endforeach; $wp_customize->add_setting('show_on_page'); $wp_customize->add_control( new Multiple_Select( $wp_customize, 'multiple_select_setting', array( 'label' => __('Pages to show', 'dd_theme'), 'section' => 'footer_bg', 'settings' => 'show_on_page', 'type' => 'select', 'type' => 'multiple-select', // The $type in our class 'choices' => $p ) ) ); } class Multiple_Select extends WP_Customize_Control { public $type = 'multiple-select'; public function render_content() { if ( empty( $this->choices ) ): return; endif; ?>
label ); ?>
link(); ?> multiple="multiple" style="height: 100%;"> choices as $value => $label ) { $selected = ( in_array( $value, $this->value() ) ) ? selected( 1, 1, false ) : ''; echo '
' . $label . '
'; } ?>
29.09.19
Reply
Anonymous
to check in the theme use && in_array(get_the_ID(),get_theme_mod('show_on_page')) ): and don't forget to add include_once ABSPATH . 'wp-includes/class-wp-customize-control.php';
29.09.19
Reply
Anonymous
Information Epoch 1758182651
When in doubt, use brute force.
Home
Notebook
Contact us