Is_active_侧边栏()不起作用

时间:2014-01-15 作者:Francesco Craparo

为什么is\\u active\\u sidebar()函数返回的总是false?

作用php代码:

if ( function_exists(\'register_sidebar\') ) {   
register_sidebar(array( 
    \'name\' => \'Footer Column 2\',
    \'id\' => \'footer-column-2\', // I also added the ID but doesn\'t work 
    \'before_widget\' => \'<div id="%1$s" class="omc-footer-widget %2$s">\',    
    \'after_widget\' => \'</div>\', 
    \'before_title\' => \'<h4>\',   
    \'after_title\' => \'</h4>\'   
));
}
页脚。php代码:

<?php if ( is_active_sidebar( \'footer-column-2\' ) ) : ?>    

    <div class="omc-footer-widget-column">  

            <?php dynamic_sidebar( \'Footer Column 2\' ); ?>

    </div><!--- /second-footer-column -->

<?php endif; ?>
我试过用这个名字或id,但没用。有什么想法吗?

谢谢

编辑:我有更多动态边栏,我使用此代码注册这些边栏:

//register custom sidebars
add_action( \'widgets_init\', \'register_theme_sidebars_dynamic\' );

// and this function...I think the problem is here:

function register_theme_sidebars_dynamic(){
    global $wpdb;
    //post and pages sidebars
    $widgetized_pages = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = \'omc_page_sidebar\'", \'\'));

    if($widgetized_pages){
        foreach($widgetized_pages as $w_page){
            $widget_id = strtolower(str_replace(\' \', \'_\', $w_page));
            register_sidebar(array(
                \'name\' => $w_page,
                \'id\'   => \'jw_widgetsection_\'.$widget_id,
                \'description\'   => \'\',
                \'before_widget\' => \'\',
                \'after_widget\' => \'\',
                \'before_title\' => \'\',
                \'after_title\' => \'\'
            ));
         }// For each
    }//End If


   }


1 个回复
最合适的回答,由SO网友:ucon89 整理而成

在你的函数中试试这个。php

function your_widget(){

register_sidebar(array( 
    \'name\' => \'Footer Column 2\',
    \'id\' => \'footer-column-2\', // I also added the ID but doesn\'t work 
    \'before_widget\' => \'<div id="%1$s" class="omc-footer-widget %2$s">\',    
    \'after_widget\' => \'</div>\', 
    \'before_title\' => \'<h4>\',   
    \'after_title\' => \'</h4>\'   
));

}

add_action( \'widgets_init\', \'your_widget\' );
调用页脚。ID为的php。

<?php if ( is_active_sidebar( \'footer-column-2\' ) ) : ?>    

    <div class="omc-footer-widget-column">  

            <?php dynamic_sidebar( \'footer-column-2\' ); ?>

    </div><!--- /second-footer-column -->

<?php endif; ?>

结束

相关推荐