Skip to content

Instantly share code, notes, and snippets.

@web2feel
Last active December 16, 2015 05:21
Show Gist options
  • Select an option

  • Save web2feel/9b51eed5bd786e890e15 to your computer and use it in GitHub Desktop.

Select an option

Save web2feel/9b51eed5bd786e890e15 to your computer and use it in GitHub Desktop.
Customizer for slider
// Custom control for carousel category
if (class_exists('WP_Customize_Control')) {
class WP_Customize_Category_Control extends WP_Customize_Control {
public function render_content() {
$dropdown = wp_dropdown_categories(
array(
'name' => '_customize-dropdown-category-' . $this->id,
'echo' => 0,
'show_option_none' => __( '— Select —' ),
'option_none_value' => '0',
'selected' => $this->value(),
)
);
$dropdown = str_replace( '<select', '<select ' . $this->get_link(), $dropdown );
printf(
'<label class="customize-control-select"><span class="customize-control-title">%s</span> %s</label>',
$this->label,
$dropdown
);
}
}
}
// Register slider customizer section
add_action( 'customize_register' , 'carousel_options' );
function carousel_options( $wp_customize ) {
$wp_customize->add_section(
'carousel_section',
array(
'title' => 'Carousel settings',
'priority' => 202,
'capability' => 'edit_theme_options',
)
);
$wp_customize->add_setting(
'carousel_setting',
array(
'default' => '',
)
);
$wp_customize->add_control(
new WP_Customize_category_Control(
$wp_customize,
'carousel_category',
array(
'label' => 'Category',
'settings' => 'carousel_setting',
'section' => 'carousel_section'
)
)
);
$wp_customize->add_setting(
'count_setting',
array(
'default' => '6',
)
);
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'carousel_count',
array(
'label' => __( 'Number of posts', 'theme_name' ),
'section' => 'carousel_section',
'settings' => 'count_setting',
'type' => 'text',
)
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment