我创建了一个Wordpress定制器选项来显示面包屑。无论设置为什么,它始终显示。如果未设置则不显示。
Functions.php
/* MAIN SETTINGS - Breadcrumb Setting */
$wp_customize->add_setting('swag_main_breadcrumb_top_homepage', array(
'default' => 'main-breadcrumb-top-homepage-none'
));
$wp_customize->add_control('swag_main_breadcrumb_top_homepage', array(
'label' => 'Top Breadcrumb On Homepage',
'section' => 'swag_main_design_section',
'active_callback' => 'main_show_breadcrumb_settings_callback',
'type' => 'select',
'choices' => array(
'main-breadcrumb-top-homepage-none' => __('None'),
'main-breadcrumb-top-homepage-design-1' => __('Design 1'),
'main-breadcrumb-top-homepage-design-2' => __('Design 2'),
'main-breadcrumb-top-homepage-design-3' => __('Design 3'),
)
));
/* MAIN SETTINGS - Breadcrumb Setting */
$wp_customize->add_setting('swag_main_breadcrumb_top_otherpage', array(
'default' => 'main-breadcrumb-top-otherpage-none'
));
$wp_customize->add_control('swag_main_breadcrumb_top_otherpage', array(
'label' => 'Top Breadcrumb On Otherpage',
'section' => 'swag_main_design_section',
'active_callback' => 'main_show_breadcrumb_settings_callback',
'type' => 'select',
'choices' => array(
'main-breadcrumb-top-otherpage-none' => __('None'),
'main-breadcrumb-top-otherpage-design-1' => __('Design 1'),
'main-breadcrumb-top-otherpage-design-2' => __('Design 2'),
'main-breadcrumb-top-otherpage-design-3' => __('Design 3'),
)
));
Header.php
$swag_main_breadcrumb_top_homepage = get_theme_mod('$swag_main_breadcrumb_top_homepage');
if (isset($swag_main_breadcrumb_top_homepage) && $swag_main_breadcrumb_top_homepage=='') {
$swag_main_breadcrumb_top_homepage ='';
}
$swag_main_breadcrumb_top_otherpage = get_theme_mod('$swag_main_breadcrumb_top_otherpage');
if (isset($swag_main_breadcrumb_top_otherpage) && $swag_main_breadcrumb_top_otherpage=='') {
$swag_main_breadcrumb_top_otherpage ='';
}
<?php
if (is_front_page()) {
if (isset($swag_main_breadcrumb_top_homepage) && $swag_main_breadcrumb_top_homepage !='main-breadcrumb-top-homepage-none') {
swag_breadcrumb();
}
} else {
if (isset($swag_main_breadcrumb_top_otherpage) && $swag_main_breadcrumb_top_otherpage !='main-breadcrumb-top-otherpage-none') {
swag_breadcrumb();
}
}
?>
我在做错什么以及如何解决?
答案 0 :(得分:1)
看起来您的代码中有错别字。例如
get_theme_mod('$swag_main_breadcrumb_top_otherpage')
应该像
get_theme_mod('swag_main_breadcrumb_top_otherpage')
。