寄存器侧边栏函数问题

时间:2018-05-08 作者:SENSE agency

这个函数有什么问题?

function init(){
    //go through each sidebar and register it
    $sidebars = sidebar_generator::get_sidebars();


    if(is_array($sidebars)){
        foreach($sidebars as $sidebar){
            $sidebar_class = sidebar_generator::name_to_class($sidebar);
            register_sidebar(array(
                \'name\'=>$sidebar,
                \'id\' => \'new-sidebars\',
                \'before_widget\' => \'<div class="sb_widget">\',
                \'after_widget\' => \'</div>\',
                \'before_title\' => \'<h4>\',
                \'after_title\' => \'</h4>\',
            ));
        }
    }
}
以下是日志:

注意:register\\u侧栏调用不正确。“侧栏”侧栏的参数数组中未设置id。默认设置为“侧栏-1”。手动将id设置为“侧栏-1”,以使此通知静音并保留现有侧栏内容。有关详细信息,请参阅WordPress中的调试。(此消息是在版本4.2.0中添加的。)in/home/incentiv/public\\u html/wp包含/函数。php在线4147

注意:register\\u侧栏调用不正确。“页脚”侧栏的参数数组中未设置id。默认设置为“侧栏-2”。手动将id设置为“侧栏-2”,以使此通知静音并保留现有侧栏内容。有关详细信息,请参阅WordPress中的调试。(此消息是在版本4.2.0中添加的。)in/home/incentiv/public\\u html/wp包含/函数。php在线4147

注意:register\\u侧栏调用不正确。“Contact Top”侧栏的参数数组中未设置id。默认设置为“侧栏-3”。手动将id设置为“侧栏-3”,以使此通知静音并保留现有侧栏内容。有关详细信息,请参阅WordPress中的调试。(此消息是在版本4.2.0中添加的。)in/home/incentiv/public\\u html/wp包含/函数。php在线4147

2 个回复
SO网友:Suresh Sapkota

看起来,您并没有向侧栏提供任何id,这会导致从上述代码为每个侧栏生成唯一id的问题。那么,您是否将代码替换为这些行。希望这能帮助我们解决你的问题。你可以找到一个好的solution 与您的问题类似。(更新)

public static function init(){
        //go through each sidebar and register it
        $sidebars = sidebar_generator::get_sidebars();
        //$sidebars = $this->get_sidebars();
        if(is_array($sidebars)){
            foreach($sidebars as $key => $sidebar){
                $sidebar_class = sidebar_generator::name_to_class($sidebar);
                register_sidebar(array(
                                        \'id\' => $key,
                    \'name\'=>$sidebar,
                    \'before_widget\' => \'<div id="%1$s" class="widget %2$s">\',
                    \'after_widget\' => \'</div>\',
                    \'before_title\' => \'<h4 class="sb_title">\',
                    \'after_title\' => \'</h4>\',
                    ));
                }
            }
        }

SO网友:SENSE agency

非常感谢。现在,在我将函数更改为static之后,我有了关于这个新函数的日志`函数admin\\u print\\u scripts(){wp\\u print\\u scripts(array(\'sack\');?>函数add\\u sidebar(sidebar\\u name){

                var mysack = new sack("<?php echo site_url(); ?>/wp-admin/admin-ajax.php" );    

                mysack.execute = 1;
                mysack.method = \'POST\';
                mysack.setVar( "action", "add_sidebar" );
                mysack.setVar( "sidebar_name", sidebar_name );
                mysack.encVar( "cookie", document.cookie, false );
                mysack.onError = function() { alert(\'Ajax error. Cannot add sidebar\' )};
                mysack.runAJAX();
                return true;
            }

            function remove_sidebar( sidebar_name,num )
            {

                var mysack = new sack("<?php echo site_url(); ?>/wp-admin/admin-ajax.php" );    

                mysack.execute = 1;
                mysack.method = \'POST\';
                mysack.setVar( "action", "remove_sidebar" );
                mysack.setVar( "sidebar_name", sidebar_name );
                mysack.setVar( "row_number", num );
                mysack.encVar( "cookie", document.cookie, false );
                mysack.onError = function() { alert(\'Ajax error. Cannot add sidebar\' )};
                mysack.runAJAX();
                //alert(\'hi!:::\'+sidebar_name);
                return true;
            }
        </script>
    <?php
}`

结束

相关推荐