1
我試圖創建一個多選框類別下拉,即時通訊有問題。多選擇類別WordPress定製控件
下面是自定義控件類:
class Nt_Customize_Control_Multiple_Select extends WP_Customize_Control {
/**
* The type of customize control being rendered.
*/
public $type = 'multiple-select';
/**
* Displays the multiple select on the customize screen.
*/
public function render_content() {
if (empty($this->choices))
return;
?>
<label>
<span class="customize-control-title"><?php echo esc_html($this->label); ?></span>
<select <?php $this->link(); ?> multiple="multiple" style="height: 100%;">
<?php
foreach ($this->choices as $value => $label) {
$selected = (in_array($value, $this->value())) ? selected(1, 1, false) : '';
echo '<option value="' . esc_attr($value) . '"' . $selected . '>' . $label . '</option>';
}
?>
</select>
</label>
<?php }}
定製選項:
$wp_customize->add_setting('nt_featured_cat', array(
'default' => 0,
'transport' => 'refresh',
'sanitize_callback' => 'nt_sanitize_cat'));
$wp_customize->add_control(
new Nt_Customize_Control_Multiple_Select (
$wp_customize,
'nt_featured_cat',
array(
'settings' => 'nt_featured_cat',
'label' => 'Featured category',
'section' => 'nt_blog_archive_section', // Enter the name of your own section
'type' => 'multiple-select', // The $type in our class
'choices' => nt_cats()
)
)
);
和分類功能:
function nt_cats() {
$cats = array();
$cats[0] = "All";
foreach (get_categories() as $categories => $category) {
$cats[$category->term_id] = $category->name;
}
return $cats;
}
任何幫助將不勝感激,謝謝!
什麼是您所遇到的問題?你有錯誤嗎? –
@AndrewMyers我用'WP_Query'做了一個循環,類別不打印任何東西,'var_dump'返回'STRING''(LENGTH = 0)' – HiroHito